Support » Plugins » calling a widget from anywhere in a theme

  • So we can call any widget anywhere in a theme using the_widget. Bono has a page about the_widget here

    We can call the default pages widget like this:


    We can custom wrap it like this:

    $args = array(
        'before_widget' => '<div class="widget">',
        'after_widget'  => '</div></div>',
        'before_title'  => '<div class="widgetTittle">',
        'after_title'   => '</div><div class="widgetBody">' );
    the_widget('WP_Widget_Pages', null, $args);

    We can even tell it to custom sort it like so:

    the_widget('WP_Widget_Pages', 'sortby=post_modified', $args);

    But for the love of god, does anyone know how to get access to the stored widget options? I’m going out of my mind trying to figure it out.


Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter dans7919



    This work only for generic widgets?
    If i install some widget, how can i call it from anywhere?

    Also, is there a way to obtain the list of widgets on any sidebar from code?

    Thanks in advance

    Also, looking for an answer on this one.

    I will continue to research and report if I find anything.

    do you mean from within posts? Or anywhere in your template? You can just add more widget areas anywhere in your theme really.

            'before_widget' => '<div id="%1$s" class="widget %2$s">',
            'after_widget' => '</div>',
            'before_title' => '<h3>',
            'after_title' => '</h3>',

    in functions.php, (within the <?php of course) creates another ‘sidebar’ that is a widget area

    <div class="widgetBox">
    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('moreWidgets') ) : ?>
    <h3>Archives</h3><p>All entries, chronologically...</p><ul><?php wp_get_archives('type=monthly&limit=12'); ?> </ul>
    <?php endif; ?>

    Can be dropped in any template where you want a widget. Then add .widgetBox (of course you’ll need to change the class name on a per widget area) to your css and style the area. This is set up to display Archives as default, which goes away when you add a widget.

    RVoodoo… My research seems to keep yielding results similar to what you have written.

    I was able to make a call to my custom Widget from anywhere within my Theme with the following code:

    <?php $track = new Tracking();
          echo $track->widget($args, $instance); ?>

    My custom widget is “Tracking” and it extends “WP_Widget”.

    The problem with that solution is… the user settings that are made in the Admin Panel for my widget are NOT being returned in my custom widget call (above). I am guessing due to the fact I am instantiating a new Tracking object.

    I’ll try what you suggested and report back. I just didn’t want to have to write anything additional into the functions.php file. That reasoning does make sense if I told you the overall picture of what I am trying to accomplish.

    Ok. Hats off to RVoodoo for urging me towards working solution.

    Wasn’t how I initially planned on doing it, but it worked.

    I was trying a custom written implementation of “the_widget() function” that is listed on this website:

    But, that didn’t work for me. I couldn’t even Activate their demo plugin. WordPress said there was an error when I tried.

    Thanks again. That was the first response I believe I have recieved for any of my question posts.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘calling a widget from anywhere in a theme’ is closed to new replies.