Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

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).

share|improve this answer
    
Great answer. One other thing, you could also use the wp_footer action hook to add it to the theme. –  bungeshea Dec 22 '12 at 3:41
    
@bungeshea I tried that in Twenty Eleven: the result was not very convincing because the stylesheet is not prepared for that. You have to to change the theme files. –  toscho Dec 22 '12 at 3:43
    
It works in some themes, other themes … not so much. –  bungeshea Dec 22 '12 at 3:44
    
Thanks for taking the time to explain. This is exactly what I was looking for. –  user1822824 Dec 22 '12 at 5:21
add comment

I think as usually you do

Hope it helps

share|improve this answer
2  
This answer has nothing to do with the question! Read the question properly, and then read it again –  bungeshea Dec 22 '12 at 3:42
add comment

Your Answer

 
discard

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.