[Resolved] Adding widget area after archives description

Home Forums Support Adding widget area after archives description

  • This topic has 7 replies, 2 voices, and was last updated 6 months ago by David.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1121517
    byo

    Hi,
    I’m trying to add a widget area after: generate_after_archive_description
    If i add the code in theme root folder “archives.php” file; the widgets does not display very well (hidden behind the posts grid)

    If i put the code in archives.php file found in (inc/structure/)
    The widget display very well

    I can’t use it in (inc/structure/) if themes update i will lose it,

    Any idea what causing this and how to fix it?

    #1121643
    David
    Staff
    Customer Support

    Hi there,

    we are looking at implementing a new Hook that comes just before the Loop to make this sort of thing easier. In the meantime what happens if you use the: generate_after_archive_title hook?

    #1121682
    byo

    you mean use the hook in functions.php to display the widget?
    I’m using “widget visibility” plugin for managing where every widget is displayed
    i have a good number of widgets, if i had to use this method:
    https://docs.generatepress.com/article/using-hooks/

    it will be very hard to manage

    If there is a way to display the whole widget area, and let the plugin “widget visibility” manage the rest, that will be good.

    #1121728
    David
    Staff
    Customer Support

    Once you have registered your custom Widget Area you would then hook that into generate_after_archive_title via your functions.php or using the GP Hook Element.

    You can then manage what is displayed in that widget area using the Widget Visibility plugin.

    #1121861
    byo

    There is documentation on how to that in themes like Genesis, i already used it, but Generatepress, there is not, or i could not find it:

    //* Add widget area in gp archive pages
    add_action( 'generate_after_archive_title', 'add_widget_area_gp' );
    function add_widget_area_gp() {
    	if ( is_archive() )
    	gp_widget_area ('archive-widget', array(
            'before' => '<div class="archive-widget"><div class="wdgt-aarchive">',
            'after' => '</div></div>',
    	) );
    }

    This code does not work, i could not find what to replace this with “gp_widget_area” ?

    #1121873
    David
    Staff
    Customer Support

    This article in the Codex explains how to display your widget area:

    https://codex.wordpress.org/Widgetizing_Themes#How_to_display_new_Widget_Areas

    The code they provided can be simply added to your hook function

    #1121906
    byo

    Finally i assembled the puzzle lol, i saw your code (in the documentation) and i tought that’s it’s only for adding text not code….Ahhh.. lol

    Here is the code i used,

    add_action( 'generate_after_archive_description','add_widget_after_archive_description' );  
    function add_widget_after_archive_description() { ?> 
    
    <?php if ( is_active_sidebar( 'agp-widget-area-after-description-archives' ) ) : ?>
    	<div id="after-description-sidebar" class="aftr-description-widget-sidebar widget-area" role="complementary">
    		<?php dynamic_sidebar( 'agp-widget-area-after-description-archives' ); ?>
    	</div><!-- #primary-sidebar -->
    <?php endif; ?>
    
    <?php }

    it displays perfectly

    Thanks a lot

    #1122079
    David
    Staff
    Customer Support

    Glad to hear that 🙂

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