Custom general settings (textarea field) don't output HTML correctly

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' ) 
    );
}

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

I display it using:

echo get_option( 'produktyseoopis' );

Topic wp-editor options Wordpress

Category Web


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.


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' ) );

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.