Most Genesis child themes now add the After Entry widget area to the bottom of single blog posts. It’s added after the blog post and before the comments section. The most common use for this widget area is to add a call-to-action, such as a newsletter signup box. But often business website owners need an after entry area on pages or custom post types, such as their portfolio or testimonials pages.
Add the After Entry Widget Area to Posts
You can add theme support for the after entry widget area to your functions.php file. Edit the file with a text editor.
<?php
// Remove opening php tag when using
// Add support for after entry widget
add_theme_support( 'genesis-after-entry-widget-area' );
Add the After Entry Widget Area to Posts and Pages
If you want to add after entry to posts and pages, you will need to use the following code instead.
Again this code is added to your child theme functions.php file.
<?php
// Remove opening php tag when using
// Add support for after entry widget
add_theme_support( 'genesis-after-entry-widget-area' );
// Remove after entry widget
remove_action( 'genesis_after_entry', 'genesis_after_entry_widget_area' );
// Add after entry widget to posts and pages
add_action( 'genesis_after_entry', 'amethyst_after_entry', 9 );
function amethyst_after_entry() {
if ( ! is_singular( array( 'post', 'page' )) )
return;
genesis_widget_area( 'after-entry', array(
'before' => '<div class="after-entry widget-area">',
'after' => '</div>',
) );
}
Explanation of the Code
First you need to add theme support for the widget area, as before.
// Add support for after entry widget
add_theme_support( 'genesis-after-entry-widget-area' );
Next unhook (remove) the widget from after entry, so you can add pages to it.
// Remove after entry widget
remove_action( 'genesis_after_entry', 'genesis_after_entry_widget_area' );
Then you can hook it again after entry with a function (amethyst_after_entry). You will also need to add a priority number of 9 or less to add the after entry widget back in above the comments section.
// Add after entry widget to posts and pages
add_action( 'genesis_after_entry', 'amethyst_after_entry', 9 );
Next in the function (amethyst_after_entry), you want to return without doing anything, if you are not on a post or page.
function amethyst_after_entry() {
if ( ! is_singular( array( 'post', 'page' )) )
return;
The last section adds the widget area, and finishes with a close bracket.
genesis_widget_area( 'after-entry', array(
'before' => '<div class="after-entry widget-area">',
'after' => '</div>',
) );
}
Add the After Entry Widget Area to Posts and Custom Post Types
When you add after widget area support for custom post types, you will need to find the slug. This can be found in the url in your browser bar when you are on a custom post type page. It will be just before the post title in the url. This image shows a portfolio custom post type.
<?php
// Remove opening php tag when using
// Add support for after entry widget
add_theme_support( 'genesis-after-entry-widget-area' );
// Remove after entry widget, so you can add to it
remove_action( 'genesis_after_entry', 'genesis_after_entry_widget_area' );
// Add after entry widget to posts, testimonial, and portfolio
add_action( 'genesis_after_entry', 'amethyst_after_entry', 9 );
function amethyst_after_entry() {
if ( ! is_singular( array( 'post', 'testimonial, 'portfolio' )) )
return;
genesis_widget_area( 'after-entry', array(
'before' => '<div class="after-entry widget-area">',
'after' => '</div>',
) );
}
The explanation of the code is the same as before, but this time we added it to single posts and custom post types of testimonial and portfolio. You could also add pages to the array, as before. Be sure to replace ‘testimonial’ and ‘portfolio’ with your own custom post types.
You can add anything you like to your after entry widget area.
Leave a Reply