Putting a widget under my content area

Over on my main website I wanted to put a widget I had recently started using but not on the sidebar or footer where my current widgets resided. I needed a new widget area and was delighted with how simple it was to implement.

It required 3 edits. One to functions.php, one to single.php and one to page.php

In Functions.php we added

register_sidebar(array(
‘name’ => __( ‘Popular Content’ ),
‘id’ => ‘under-content’,
‘description’ => __( ‘Widgets in this area will be shown under the content.’ ),
‘before_title’ => ‘<h2>’,
‘after_title’ => ‘</h2>’
));

This has the effect of creating a brand new section in the Widgets panel, called Popular Content. It will have a title of Popular Content in a H2 tag.

Popular Content

We now can add widgets to this area, but we need to place it somewhere. In my case I wanted it under my content. I needed to find the_content(); and below it place

<?php if (!dynamic_sidebar(‘under-content’) ) : ?>
<?php endif; ?>

The under-content is a reference to the ID I used in the functions.php. Whoila, Your widgets will now server under your content. In my application, I was removing a useless related posts plugin and using the Jetpack Top Posts widget in Image display option to render 6 of the top posts under every post. This is aimed at providing more relevant and up to date content than the related posts plugin as all the content is recent, and active and being viewed by lots of people.

Leave a Reply