WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've created a simple one-off widget to let the admin change some copy on the home page, but the widget isn't showing its contents.

On the home page, I have this code: <?php the_widget('home_widget'); ?>

And this is the source code for the widget itself, as it appears in my functions.php file (it's Jeff Starr's Clean Markup Widget):

// Clean Markup Widget @ http://perishablepress.com/clean-markup-widget/
add_action('widgets_init', create_function('', 'register_widget("home_widget");'));
class home_widget extends WP_Widget {
    function __construct() {
        parent::WP_Widget('home_widget', "home page box",
                          array('description'=>"The contents of the home page box"));
    function widget($args, $instance) {
        $markup = $instance['markup'];
        if ($markup) echo $markup;
    function update($new_instance, $old_instance) {
        $instance = $old_instance;
        $instance['markup'] = $new_instance['markup'];
        return $instance;
    function form($instance) {
        if ($instance) $markup = esc_attr($instance['markup']);
        else $markup = __('Sample markup', 'markup_widget'); ?>
            <label for="<?php echo $this->get_field_id('markup'); ?>"><?php _e('Markup/text'); ?></label><br />
            <textarea class="widefat" id="<?php echo $this->get_field_id('markup'); ?>" name="<?php echo $this->get_field_name('markup'); ?>" type="text" rows="16" cols="20" value="<?php echo $markup; ?>"><?php echo $markup; ?></textarea>
<?php }

The widget looks and works perfectly in the Admin tool, and I can add text and save it, etc. But nothing displays on the home page. How can I get it to display the widget contents?

To be clear: while I am putting the widget into a sidebar on the Admin interface (because you have to), I don't want to display the sidebar (since I have other widgets in there). I just want this one-off widget to display its contents on the home page. Very simple.

share|improve this question
Thanks, I tried that solution but it didn't work for me. – Eric Jun 21 '13 at 20:26
You could check out this plugin if you want an alternate way to display any widget in page/post content: wordpress.org/plugins/amr-shortcode-any-widget – Michelle Jul 15 '13 at 18:03
Thanks @Michelle. – Eric Jul 15 '13 at 21:39
up vote 2 down vote accepted

You can force a particular widget that you have modified on the backend to show up if you can identify is sufficiently. I consider that very prone to error.

You should be able to get the_widget to work if you pass enough detail through the (up to) three parameters-- like this:

the_widget('home_widget',array('markup' => 'Yay')); 

But you don't get to configure that from the backend.

I would suggest that if you are going to use a widget, create a sidebar for the widget.

share|improve this answer
Ok, I see now what the_widget does... thank you. Sounds like widgets are really built to live in sidebars and they don't like being outside of them. :-) Could I ask you to look at this question again? It's what led me to widgets in the first place. wordpress.stackexchange.com/questions/103433/… – Eric Jun 21 '13 at 20:29
@Michelle : That is better posted as a comment to the question than as a comment to this answer. – s_ha_dum Jul 15 '13 at 15:00
Good point, @s_ha_dum - I've moved it. Thanks! – Michelle Jul 15 '13 at 18:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.