Site logo

[Support request] How to add widget below the post?

Home Forums Support [Support request] How to add widget below the post?

Home Forums Support How to add widget below the post?

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #2539681
    Jericho

    Hello GeneratePress Support,

    I am reaching out to inquire about how I can place a popular posts widget before/after the comment section of my blog post.

    I have been using a popular posts widget in the right sidebar of my website, but as I am not using a sidebar anymore, I would like to place it in a different location. I would like to place the widget in either generate_before_comments_container or generate_after_main_content depending on my preference.

    Could you please provide me with instructions or code snippets on how to achieve this? I would appreciate any help you can provide.

    Thank you very much for your time and assistance.

    Best regards,
    Jericho

    #2540100
    David
    Staff
    Customer Support

    Hi there,

    you can register you’re own Widget area with the following PHP Snippet:

    function db_after_content_widget() {
    
    	register_sidebar( array(
    		'name'          => 'After Content Widget',
    		'id'            => 'after_content_widget',
    		'before_widget' => '<div>',
    		'after_widget'  => '</div>',
    	) );
    
    }
    add_action( 'widgets_init', 'db_after_content_widget' );
    
    add_action('generate_after_main_content', function(){
    	if ( is_active_sidebar( 'after_content_widget' ) && is_single() ) : ?>
    		<div id="after-content-sidebar" class="widget-area" role="complementary">
    			<?php dynamic_sidebar( 'after_content_widget' ); ?>
    		</div>
    	<?php endif;
    });

    In this line: add_action('generate_after_main_content', function(){ you can set which Hook you want to use.

    #2540613
    Jericho

    Hi David,

    It’s working but the alignment is not quite right. Could you assist me with adjusting the CSS so that the width matches the content?

    Thank you for your help!

    #2540616
    Fernando
    Customer Support

    Hi Jericho,

    What hook did you use? Can you try generate_after_entry_content?

    #2540620
    Jericho

    Hi Fernando,

    The default one that David gave. I believe it’s `generate_after_main_content

    #2540636
    Fernando
    Customer Support

    Try adding this through Apperance > Customize > Additional CSS:

    div#after-content-sidebar {
        max-width: 600px;
        margin-left: auto;
        margin-right: auto;
    }
    #2540639
    Jericho

    Perfect! Many thanks to David and Fernando for the help!

    #2540653
    Fernando
    Customer Support

    You’re welcome, Jericho!

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.