最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - Is it possible to place a WordPress widget into the main page layout?

programmeradmin4浏览0评论

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
  • With 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
Add a comment  | 

1 Answer 1

Reset to default 0

of course you can, you can place widgets wherever you want in your page:

  1. 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.

  2. 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.

发布评论

评论列表(0)

  1. 暂无评论