Add New Footer Widget Area with Limited Options?

I’m trying to add a new footer widget area to my theme. I was able to add the new footer widget area and it works correctly. But I would like to limit what can be done with the widget area by the end user, right now the user can add any widget that they wish to the new footer widget area.

I would like to limit the widget area to a line of text only such as a copyright statement. Is this possible with widget areas? How should I go about limiting it to just a line of text?

2 Answers
2

Widget areas are the wrong tools for what you need. They are built to offer a choice. Breaking that would be very difficult … and hard to understand for the user.

Alternative: Use a custom setting, for example in wp-admin/options-general.php where the tagline and the site title is. There is even a hook for such additions:

do_settings_sections('general');

First, wait for the action admin_init, and then register a new settings field:

add_filter( 'admin_init', 'wpse_76943_register_setting' );

function wpse_76943_register_setting()
{
    register_setting( 'general', 'footer_text', 'trim' );

    add_settings_field(
        'footer_text',
        'Footer text',
        'wpse_76943_print_input',
        'general',
        'default',
        array ( 'label_for' => 'footer_text' )
    );
}

Easy. Now we need a function to print that field. Use a classic text input field with a class large-text to make it wide enough:

function wpse_76943_print_input()
{
    $value = esc_attr( get_option( 'footer_text' ) );
    print "<input type="text" value="$value" name="footer_text" id='footer_text'
    class="large-text" />
    <span class="description">Text for the footer.</span>";
}

enter image description here

That’s all!

To use the footer text in your theme just check if there is a value, then print it:

if ( $footer_text = get_option( 'footer_text' ) )
    print "<p>$footer_text</p>";

I have written a plugin doing almost the same thing, it is just more flexible: Public Contact Data (Download as ZIP archive).

Leave a Comment