0

I add my custom fields in genearal settings page. One of them using Wordpress Editor - there i insert my HTML content. I creeated it using simple snippet:

add_action( 'admin_init', 'register_settings_wpse_57647' );




function register_settings_wpse_57647() 
{
    register_setting( 
        'general', 
        'opisproduktyseop',
        'esc_html'
    );
    add_settings_section( 
        'site-guide', 
        'Publishing Guidelines', 
        '__return_false', 
        'general' 
    );
    add_settings_field( 
        'opisproduktyseop', 
        'Enter custom message', 
        'print_text_editor_wpse_57647', 
        'general', 
        'site-guide' 
    );
}  

function print_text_editor_wpse_57647() 
{
    $the_guides = html_entity_decode( get_option( 'opisproduktyseop' ) );
    echo wp_editor( 
        $the_guides, 
        'sitepublishingguidelines', 
        array( 'textarea_name' => 'opisproduktyseop' ) 
    );
}

enter image description here

The problem starts when i try display content from this field in my theme. HTML don't works:

enter image description here

I display it using:

echo get_option( 'produktyseoopis' );
0

It's because you're using esc_html to sanitize the setting, which converts all the <,> etc. into HTML entities, like &gt;, which render as < but aren't treated as those characters in terms of HTML, which is why tags aren't rendering correctly. esc_html is supposed to be use for outputting HTML so that the markup is visible to the reader.

If you want to sanitize HTML, use wp_kses_post as the sanitization callback.

EDIT: Suggest wp_kses_post, rather than wp_kses, as per Tom's comment.

|improve this answer|||||
  • 1
    wp_kses_post specifically, and there's the_content filter too if shortcodes and embeds are wanted – Tom J Nowell Aug 31 '17 at 13:38
-2

Ok. i was solved it right now! When i display it i put it wit html_entity_decode()

echo html_entity_decode( get_option( 'produktyseoopis' ) );
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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