How to do it...

Follow these steps to create a widget area and place it after the post/page content:

  1. Open the wp-content/themes/twentytwentychild folder of your WordPress installation and open the functions.php file.
  2. Add the following code at the end of the file to define a new widget area:
function wpccp_chapter3_widgets_init() {
register_sidebar( array(
'name' => __('After Post Content','wpccp_ch3'),
'id' => 'after_post_content_1',
'before_widget' => '<div class="widget-column">',
'after_widget' => '</div>',
'before_title' => '<h2 class="rounded">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'wpccp_chapter3_widgets_init' );

  1. Copy the singular.php file from the wp-content/themes/twentytwenty folder to the wp-content/themes/twentytwentychild folder.
  2. Open the copied singular.php file using the code editor.
  3. Find the following line inside the singular.php file: // If comments are open or we have at least one comment, load up the comment template.
  4. Add the following code before the line in step 5 to display the new widget area:
if ( is_active_sidebar( 'after_post_content_1' ) ) : ?>
<div style="max-width: 80%;margin: 0 10%;padding: 0 60px;"
id="primary-post-content-sidebar" class="primary-post-content-
sidebar widget-area" role="complementary">
<?php dynamic_sidebar( 'after_post_content_1' ); ?>
</div><!-- #primary-sidebar -->
<?php endif;
  1. Save the file.
  2. Log in to the WordPress Dashboard as an administrator.
  3. Click the Appearance menu.
  4. Click the Widgets option.
  5. Drag and drop some widgets from the Available Widgets section to the After Post Content widget area, as shown in the following screenshot:

  1. Visit one of the posts of your site on the frontend.

Now, you will see a new area after the content of the post. This area will display the widgets you added for the After Post Content widget area:

As you can see, the widgets are displayed after the post content in the new widget area. We can also modify the style to display widgets in two columns instead of just using one column. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset