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, Valeka.net | Email: support@valeka.net

I get this:

Copyright 2018, Valeka.net | Email: <a href="mailto:support@valeka.net">support@valeka.net </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.

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

More info about customizer sanitization you can find on divpusher.com.

Share This Story, Choose Your Platform!