A look at Hooks in Genesis Framework

Hooks are provided by WordPress to allow your plugin or theme to ‘hook into’ the rest of WordPress.
With hooks, you could execute code snippet in a given area of WordPress core in order to modify, change and remove certain operations in WordPress.
There are two kinds of hooks: the Action and Filter.
The former execute codes in a PHP function at specific points throughout the WordPress Core while the latter replace specific data (such as a variable) found within an existing Action.
More information, check out this introductory guide to WordPress hooks.

Like with WordPress hooks, the Genesis theme framework include quite a number of Hooks which comes in handy when modifying its core and child-theme’s functionality.

Getting good with Genesis hooks

StudioPress’ Genesis theme framework has over fifty hooks.
For full list of Genesis hooks check out their Hook Reference page.

Let’s see some examples on how to add custom content or functions to a hook.

The genesis_after_post_title hook executes immediately after each post/page title.
This could be a perfect position to include social sharing buttons like Facebook Like and Twitter’s Tweet button.

The following code adds Facebook Like button immediately after the post/page title.


add_action( 'genesis_after_post_title', 'Like_button');

function Like_button(){
?>
<div class="fb-like" data-href="<?php the_permalink(); ?>" data-layout="standard" data-action="like" data-show-faces="true" data-share="true"></div>
<?php }

First, we tell WordPress to execute the code in Like_button PHP function immediately after the post/page title (genesis_after_post_title hook).

Don’t forget to include the JavaScript SDK ideally right after the opening <body>

How about trying to insert advert such as Adsense ads after the content of a post/page? The Genesis hook for that is the genesis_after_post_content.


function adsense_after_post() { ?>
// adsense code here
	
<?php }

add_action('genesis_after_post_content', 'adsense_after_post');
Note

The code posted above should go into your child theme’s functions.php file or in a dummy WordPress plugin.

If you find the idea of getting your hands dirty with codes daunting, consider Genesis Simple Hooks – that allows one to insert code (HTML, Shortcodes, and PHP), and attach it to any of the 50+ action hooks.

Don’t miss out!
Subscribe to My Newsletter
Invalid email address