- This topic has 7 replies, 3 voices, and was last updated 3 years, 2 months ago by
Fernando.
-
AuthorPosts
-
February 20, 2023 at 4:32 am #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,
JerichoFebruary 20, 2023 at 8:52 am #2540100David
StaffCustomer SupportHi 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.February 20, 2023 at 7:07 pm #2540613Jericho
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!
February 20, 2023 at 7:17 pm #2540616Fernando Customer Support
Hi Jericho,
What hook did you use? Can you try
generate_after_entry_content?February 20, 2023 at 7:23 pm #2540620Jericho
Hi Fernando,
The default one that David gave. I believe it’s `generate_after_main_content
February 20, 2023 at 7:54 pm #2540636Fernando Customer Support
Try adding this through Apperance > Customize > Additional CSS:
div#after-content-sidebar { max-width: 600px; margin-left: auto; margin-right: auto; }February 20, 2023 at 7:57 pm #2540639Jericho
Perfect! Many thanks to David and Fernando for the help!
February 20, 2023 at 8:21 pm #2540653Fernando Customer Support
You’re welcome, Jericho!
-
AuthorPosts
- You must be logged in to reply to this topic.