As the question suggests, can a widget be placed with the main body of a page rather than in a side-column?
I guess this is plugin-specific but generally, if the functionality is placed on a side-bar then does that "restrict" it to that section of the layout?
As the question suggests, can a widget be placed with the main body of a page rather than in a side-column?
I guess this is plugin-specific but generally, if the functionality is placed on a side-bar then does that "restrict" it to that section of the layout?
Share Improve this question asked Sep 17, 2020 at 7:31 HenryHenry 9831 gold badge8 silver badges31 bronze badges 1 |1 Answer
Reset to default 0of course you can, you can place widgets wherever you want in your page:
Define them in a callback function in your functions.php file which calls the
register_sidebar()
function, and then hook that callback to the 'widgets_init' action hook, also in your functions.php file.On the page where you wanna use it, wherever you wanna use it, print the widget with this code, by using the value you specified as the 'id' parameter when calling
register_sidebar()
in your callback:
<?php if ( dynamic_sidebar( 'id_of_ur_widget' ) ) : else : endif; ?>
Don't get distracted by the name of the function, register_sidebar
doesn't mean that your widget is a sidebar, it's just the not-so-smartly chosen name of the wp function you use to create a custom widget.
the_widget()
function you can put a widget anywhere, not just in a registered sidebar (widget area), developer.wordpress/reference/functions/the_widget – Antti Koskinen Commented Sep 18, 2020 at 10:27