Different “Text Widgets” in Sidebar on Many Different Pages?

You’re looking for custom fields. Widgets are, generally, meant to be used for far more static content.

Pages have custom fields enabled by default. You might not see them in the editor because I think they’re also hidden by default. Click ‘Screen Options’ to make sure they’re turned on.

When you create the custom field, you’ll give it a key and a value. Use the same key for each page. In your template (or sidebar) you can get the custom field like this:

<?php
    var $meta = get_post_meta($post->id, "your-key", true);

    if(!empty($meta)): 
?>
    <aside>
        <?php echo $meta; ?>
    </aside>

<?php endif; ?>

There are plenty of great plugins out there for dealing with custom fields. One benefit almost every plugin offers is making sure that the correct meta key (or keys) is always used. It’s easy to flub it when dealing with lots of content. Pods, Advanced Custom Fields and CMB2 are three very popular ones, all with a slightly different take on it.

Leave a Comment