Live a Reply

WordPress Theme Customizer HTML Output

I wanted to add in theme customizer textarea where user can add footer copyright text. Usually those sections contains link such are site url or email url. So I had problem how to output text with links as all I get was html tags convert into text signs. So instead getting this:

Copyright 2018, | Email:

I get this:

Copyright 2018, | Email: <a href=""> </a>

And here is how I solve problem. First you would see part of code from functions.php file. Note that for sanitize_callback I used wp_kses_post. That means that only html tags that would be applied trough post/page text editor can be used here.

function basic_customize_register( $wp_customize ) {
  //Copyright -----------------------------------------------------
  $wp_customize->add_section('copyright_options', array(
    'title'    => __('Copyright', 'valeka'),
    'priority' => 121,

  $wp_customize->add_setting('copyright', array( 'default'   => '', 'type' => 'theme_mod', 'sanitize_callback' => 'wp_kses_post', 'transport'   => 'refresh'));
  $wp_customize->add_control( 'copyright', array(
    'settings' => 'copyright',
    'label'   => 'Enter Copyright Text',
    'section' => 'copyright_options',
    'type'    => 'textarea'

add_action( 'customize_register', 'basic_customize_register' );

This is how it looks when we use saved html text in footer.php file. Just simple display variable with echo.

  $copyright = get_theme_mod('copyright');
  if(!isset($copyright) || !empty($copyright)) {  ?>
    <div class="copyright">
         <?php  echo($copyright);   ?>	
<?php } ?>

More info about customizer sanitization you can find on

Share on Facebook0Share on Google+0Tweet about this on Twitter