How to display my wordpress widget programmatically? How to display my wordpress widget programmatically? wordpress wordpress

How to display my wordpress widget programmatically?


Dynamically create a dynamic instance of the widget using the_widget(), eg:

<div id="xxx" class="widget-area" role="complementary">    <div id="sidebar-dyn">        <?php the_widget( 'WP_Widget_Recent_Posts' ); ?>    </div></div>


Why the need to include custom widget programatically. I mean you can simply create another sidebar that is shown only on your custom page template "product"

Further as you need to do it for your custom page, you don't even need to check for any condition. Simply put this code in your "prdouct" page template file anywhere ( where you would like to display your sidebar".

<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('Product Sidebar')) ;?>

And simply drag your widget to this sidebar from admin panel.


If the widget has a shortcode, call it using this:

<?php echo do_shortcode( $content ) ?>