Category Archives: Hooks

01) Hello Dolly

Plugins can modify the behavior and/or appearance of a website by connecting to “hooks”.

At various times while running, WordPress checks to see whether any plugins have registered functions to run at that time. Then these functions are called.

For instance, if your Plugin needs to add information to the text title, it can register a special function which is called when the the_title filter is called.

Another example is the action hook wp_footer which is checked just before the end of the generated page. Code can be inserted at that place.

Hello Dolly is an example of a plugin adding actions at two different hooks, admin_head and admin_notices.

shortened version of the Hello Dolly plugin, in two different color formatsThe above shows different color formats from two text editors: WP (since v4.9) & BBEdit.

php tag: gray/teal
comment: gold/gray
php: purple/blue
declared function: royalblue/black
called function: black/black
variable: cadetblue/black
string: red/pink

07) Hooks

At various times while running, WordPress checks to see if any plugins have functions that are registered to run at that time. If so, those functions are executed.

Plugins register their functions to execute at various times using “filter” and “action” hooks.

Action functions return nothing but true, while Filter functions are expected to return something.


Use these commands in your plugin:

 add_action( $hook, $myFunction );
 add_filter( $hook, $myFunction );

Look for these commands in the source code of the templates to see where the hooks are executed:

 do_action( "$hook" )
 apply_filters( "$hook", "what_to_filter" )

Look into the wordpress/wp-admin/admin-footer.php template to find the admin_footer_text filter hook. It looks like this:

And, look into the wordpress/wp-admin/admin-header.php template to find the admin_notices action hook.

The conditionals in the code above show that not all admin pages use the same template.


archive page – a list of posts based on a category, taxonomy, post type.

category – to access a limited set of posts.

class – 1) identifies the style to use in the HTML markup.
class – 2) the uninstantiated object in object oriented progamming (OOPS).

directory – what you see as a folder in your GUI, can be referred to as a “directory” in your command-line interface.

footer – bottom of the web page.

GUI – Graphical User Interface, pronounced goo•ey.

head – the HTML tag inside a web page holding data not displayed.

header – the top part of a web page.

hook – a place in core code made accessible to themes & plugins.

id – an identifier in CSS like class, but unique within the web page.

index – 1) points to an element of an array.
index – 2) the first HTML (or PHP) file sought within a directory.

mapping – using a domain you own to access your blog.

masking – an extreme form of mapping.

menu – list of links to pages or a category of posts.

navigation – menus to other places in a web site.

page – a “post” of the post type page.

permalink – a custom url structure, the permanent link to individual posts.

plugin – a file added to an installation of WordPress, often to provide a widget.

post – 1) a single item of “content” stored in the wp_posts database table, which is one of the five types: post, page, attachment, revision, nav_menu_item.
post – 2) a “post” of the post type post.

sanitize – author name, category, and postname get sanitized in permalinks by having spaces replaced with hyphens.

selector – in CSS, the rule set with declaration blocks (property name & value) pointing to the HTML element to style.

shortcode – a short code, enclosed in braces, that when placed as text in a post or page calls a function to create content.

sidebar – navagation links, to the right, left, or bottom.

Slack – searchable, responsive, collaborative online team communication platform w/ instant messaging and document sharing.

slider – an adjustable electronic control that moves images in a linear fashion

slug – a user-friendly short text used in a permalink.

source set – available sizes of an image that browsers can appropriately download to save bandwidth and speed load times.

style – in CSS, a rule consisting of selectors, and declaration blocks.

tag – 1) an element of the HTML markup language.
tag – 2) used like a category (but without hierarchy) to provide more detail to a post.
$tag – 3) the hook parameter in an action function.
tag, template – 4) PHP function that instructs WordPress to “do” or “get” something. Conditional tags are used in template files to change the content displayed on a particular page depending on what conditions that page matches.

table -1) HTML: a matrix consisting of rows and columns.
table -2) MySQL: The database consists of tables, each having rows of fields.

template – a PHP file controlling the structure of part of the web page.

theme – a collection of templates creating the look & feel (design) of the website.

UTC – Coordinated Universal Time is a “time standard” and not a time zone like Greenwich Mean Time (GMT) but, in practice, share the same current time.

widget – provided by a plugin to give extra function & structure; shows up in the sidebar.