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 am trying to add a custom WordPress editor field to the General Settings page in the admin. I have it working except that when you save anything with HTML it converts all the code to HTML entities so the HTML displays on the frontend as text. For example...

  1. I add a link in the Text editor as <a href="http://www.example.com">Link</a>
  2. I click to the Visual editor and everything looks normal...
    • Visual = Link
    • Text = <a href="http://www.example.com">Link</a>
  3. I click save at the bottom and when the page reloads now I get this...
    • Visual = <a href="http://www.example.com">Link</a>
    • Text = &lt;a href="http://www.example.com"&gt;Link&lt;/a&gt;

Am I missing a setting somewhere? My code currently is...

/**
 * Add Copyright text to general settings menu
 */
$custom_general_settings = new FD_Custom_General_Settings();
class FD_Custom_General_Settings
{
    function __construct()
    {
        add_filter('admin_init', array(&$this , 'register_fields'));
    }
    function register_fields()
    {
        register_setting('general', 'footer_text', 'esc_attr');
        add_settings_field('footer_text', '<label for="footer_text">'.__('Footer Text' , 'footer_text' ).'</label>' , array(&$this, 'fields_html') , 'general');
    }
    function fields_html()
    {
        $value = get_option('footer_text', '');
        wp_editor($value, 'footer_text', array('textarea_rows'=>4), false);
    }
}
share|improve this question

2 Answers 2

up vote 1 down vote accepted

I found out I needed to add html_entity_decode() around the value so my final code is...

/**
 * Add Copyright text to general settings menu
 */
$custom_general_settings = new FD_Custom_General_Settings();
class FD_Custom_General_Settings
{
    function __construct()
    {
        add_filter('admin_init', array(&$this , 'register_fields'));
    }
    function register_fields()
    {
        register_setting('general', 'footer_text', 'esc_attr');
        add_settings_field('footer_text', '<label for="footer_text">'.__('Footer Text' , 'footer_text' ).'</label>' , array(&$this, 'fields_html') , 'general');
    }
    function fields_html()
    {
        $value = html_entity_decode(get_option('footer_text', ''));
        wp_editor($value, 'footer_text', array('textarea_rows'=>4), false);
    }
}

and then to output it into the theme and maintain any shortcodes and linebreaks...

echo nl2br(html_entity_decode(do_shortcode(get_option('footer_text', ''))));
share|improve this answer

From the codex:

Note that the ID that is passed to the wp_editor() function can only be composed of lower-case letters. No underscores, no hyphens. Anything else will cause the WYSIWYG editor to malfunction.

Your code:

wp_editor($value, 'footer_text', array('textarea_rows'=>4), false);
share|improve this answer
    
Thanks for the quick response. I have modified my code, but am getting the same result... wp_editor($value, 'footertext', array('textarea_name'=>'footer_text', 'textarea_rows'=>4), false); –  Stephanie Apr 2 '13 at 23:22

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.