I love the Theme Blvd Themes. Plenty of user friendly features, like drag and drop templates and easy to use sliders. One thing I was missing was action hooks at the top and bottom of the page content. There is a themeblvd_content_top hook, but it is outside of entry-content. I wanted something closer in.
Here is a quick rundown of how to add these hooks:
The relavent code is in page-content.php so we need to copy this file completely from the alyeska theme folder to the alyeska-child theme folder. This is “old-school” WordPress hierarchy stuff, where WordPress looks in the child theme first when a template file is called for (ignoring the main theme file meaning that an update to the main theme won’t effect the child theme code). We will get back to this file in a few minutes.
Now in functions.php of the child theme we need to create a couple of fuctions that call Wordpess’s do_action() functions
0 1 2 3 4 5 6 7 |
function jma_in_entry_content_top() { do_action('jma_in_entry_content_top'); } function jma_in_entry_content_bottom() { do_action('jma_in_entry_content_bottom'); } |
do_action() is the function which is the actual “hook”. We generally wrap it like this to keep things cleaner in the body of the code.
Now back to page-content.php. It looks like this:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?php /** * The template used to over-ride page-content.php in main theme folder */ ?> <div class="article-wrap"> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <div class="entry-content"> <?php the_content(); ?> <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', TB_GETTEXT_DOMAIN ), 'after' => '</div>' ) ); ?> <?php edit_post_link( __( 'Edit', TB_GETTEXT_DOMAIN ), '<span class="edit-link">', '</span>' ); ?> </div><!-- .entry-content --> </article><!-- #post-<?php the_ID(); ?> --> </div><!-- .article-wrap (end) --> |
We just add in our two functions after lines 8 and 10 and we get this:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php /** * The template used to over-ride page-content.php in main theme folder */ ?> <div class="article-wrap"> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <div class="entry-content"> <?php jma_in_entry_content_top();//new hook ?> <?php the_content(); ?> <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', TB_GETTEXT_DOMAIN ), 'after' => '</div>' ) ); ?> <?php jma_in_entry_content_bottom();//new hook ?> <br/><br/> <?php edit_post_link( __( 'Edit', TB_GETTEXT_DOMAIN ), '<span class="edit-link">', '</span>' ); ?> </div><!-- .entry-content --> </article><!-- #post-<?php the_ID(); ?> --> </div><!-- .article-wrap (end) --> |
that’s it now we use like any other hook:
0 1 2 3 4 5 |
function page_bottom_display() { /* this code shows up right after the content normally entered for the page */ } add_action( 'jma_in_entry_content_bottom', 'page_bottom_display' ); |