Theme Hooks

If you have been developing or customizing WordPress themes or plugins, you have heard the term Hooks. Hooks is a part of Event-driven Architecture pattern that WordPress follows to ensure extensibility of the code. When a plugin or theme is written with hooks, it becomes extensible. Then it possible for other developers to improve and extend them without ever editing the core source code.

There are 2 types of Hooks available in WordPress. These are:

  •          Action Hooks: Allows you to add extra functionality at a specific point in the processing of the page.
  •          Filter Hooks: Allows you to intercept and modify data as it is processed.

How it Works

Let’s see how hook works in WordPress. Let’s assume there is an action hook below single post content, titled “after_single_content”. Now if you want to display a simple marketing message below each of your post, you have 3 options. You can edit all posts and add the marketing message, edit the single.php or add a simple function and adjoin this to “after_single_content” hook.

Let’s see how it’s done using hook:

add_action(  'after_single_content', 'custom_mkt_message'  );

function custom_mkt_message() {
	echo "Please checkout our new product.";
}

This is the simplicity and power of using hooks. If you insert this code in a custom function plugin, you won’t have to worry about theme or plugin update deleting your customizations.

Here is the list of Action hooks available in UM Theme.

Hook File
um_theme_before_header
header.php
um_theme_header
header.php
um_theme_after_header
header.php
um_theme_header_profile_before
core-header.php
um_theme_header_profile_after
core-header.php
um_theme_before_content
header.php
um_theme_before_site
header.php
um_theme_content_top
header.php
um_theme_single_post_before
single.php
um_theme_single_post_top
content-single.php
um_theme_single_post
content-single.php
um_theme_single_post_bottom
content-single.php
um_theme_single_post_after
single.php
um_theme_before_page_content
page.php
um_theme_page
content-page.php
um_theme_after_page_content
page.php
um_theme_before_footer
footer.php
um_theme_footer
footer.php
um_theme_after_footer
footer.php
um_theme_loop_before content.php
um_theme_loop_after content.php
um_theme_content_archive_header archive.php
um_theme_before_comments
comments.php
um_theme_after_comments
comments.php
um_theme_before_comments_title
comments.php
um_theme_after_comments_title
comments.php