Html entities and shortcodes in Featured Pages

Updated : Now compatible with Featured Pages Unlimited and Customizr-Pro

Customizr by default doesn’t allow you to have HTML entities or shortcodes in Featured Pages text.

This is a wise choice, because the text is trimmed by default to 200 characters. This means that you might risk to have an unclosed tag, which will result in .. a big mess 🙂 .

But with the high flexibility of Customizr and Customizr-Pro, due to its large use of hooks (thanks @nikeo), we can achieve that!

Aren’t you excited? You should!

 

Let’s see how to do that

 

Put this code in your child-theme functions.php and then you can use

a) hyperlinks, lists, spans etc., along the normal text, in the featured page text box.

( For example: <a href=”http://presscustomizr.com”>Press Customizr</a> 😉 )

b) shortcodes

( For example: [contact-form-7 id=”42″ title=”Contact form 1″]  )

$hook_prefix = 'tc_fp_';
add_action('after_setup_theme', 'rich_featured_pages_text', 50);
function rich_featured_pages_text(){
    global $hook_prefix;
    $hook_prefix = ( class_exists('TC_fpu') && version_compare( TC_fpu::$instance->plug_version, '1.4', '>') ) ? 'fpc_' : $hook_prefix;

    // Increase the default text length
    add_filter($hook_prefix.'text_length', 'my_fp_text_length');
    function my_fp_text_length(){
        return 9999; /* 9999 means ~ infinite */ 
    }

    // Allow html entities
    add_filter($hook_prefix.'text_sanitize', 'no_sanitize_text', 20, 3);
    function no_sanitize_text($text, $fp_single_id, $fp_id){
        global $hook_prefix;
        $option_prefix = ( $hook_prefix == 'fpc_') ? $hook_prefix : '';
        // grab the original text and leave the filter hook on it
        $featured_text = apply_filters( $hook_prefix.'text', tc__f( '__get_'. $option_prefix .'option' , 'tc_featured_text_'.$fp_single_id ), $fp_single_id, $fp_id );
        // return un-sanitized text with html tags
        return html_entity_decode($featured_text);
    }
    
    // Allow shortcodes
    add_filter($hook_prefix.'text_block', 'do_shortcode');
}

 

Simple, isn’t it?

 

Where to copy/paste this code? => in your functions.php file. We strongly recommend you create a child theme. Download a start-up child theme here.

Remember: you shouldn’t edit the theme’s functions.php.

Everything you need to know about child theme with Customizr here.

25 thoughts on “Html entities and shortcodes in Featured Pages”

Comments are closed.