Archived topic
Adding widget area after archives description
7 replies · Started by byo on January 4, 2020
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?
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?
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.
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.
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" ?
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
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
Glad to hear that :)