Html entities and shortcodes in Featured Pages


Note :This snippet works only with the Classical style option. The Classical style option can be enabled in Appearance > Customize > Advanced > Theme Style. More about the theme style option here


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″]  )

 

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.


Related Snippets you may also like


We can help you to implement this snippet

Coding is our job and we know WordPress inside and out. We can help you to customize your website with small chunks of code snippets like this one.

Send us your request and we'll get back to you quickly.



25 thoughts on “Html entities and shortcodes in Featured Pages

  • Menaka S

    Hi,
    Add this to your child theme’s functions.php
    add_filter(‘tc_fp_text_sanitize’, ‘myfptext’);
    function myfptext($excerpt){
    $excerpt = strip_shortcodes( $excerpt );
    $excerpt = wptexturize( $excerpt );
    $excerpt = convert_chars( $excerpt );
    $excerpt = wpautop( $excerpt );
    $excerpt = shortcode_unautop( $excerpt );
    $excerpt = str_replace(‘]]>’, ‘]]>’, $excerpt );
    //Any other processing that you want to do

    }

    • iamhungrygeek

      Hey thanks for your response. Unfortunately that snippet prevents the ‘manual’ excerpt from working – i.e. when you want to specify the text to be used instead of the excerpt (in the Customizer). Also, it does not remove the image caption text.

        • iamhungrygeek

          So say you have a post with the image right on top with a caption, say “The storefront of the cafe”, followed by the opening text, e.g. “This cafe is new and just opened last week.”.

          By default the Featured Pages excerpt will return “The storefront of the cafe This cafe is new and just opened last week.”

          The desired output is similar to what the slider is already doing, i.e. just “This cafe is new and just opened last week.” It should not be returning the image caption text.

          Please let me know if you need more info!

          • Menaka S

            Hi iamhungrygeek,
            I understand. I assume that you do not have custom text for featured pages and use the excerpt from the page’s content.
            Try adding this to your child theme’s functions.php

  • iamhungrygeek

    Is there a way to make the Featured Pages excerpt work like the slider excerpt? For example it should remove the [image caption] tags AND all the text within the image caption tags.

    Using this code snippet it removes the [image caption] but it leaves the text inside untouched.

  • Marcos

    Now worked well.
    I think there is any issue with the characters in the code text. When I clicked “Open code in new window”, copy and paste in my editor, the error disappeared.
    I think the problem was about the blank characters before “global $hook prefix;”

  • Marcos

    I have the same problem with the global $hook_prefix;
    I think it not possible to use global under a function.

    Any solution?

  • Sally

    copied and pasted all three to notepad but it broke the site completely even when taken out again!
    $hook_prefix = ( class_exists(‘TC_fpu’) && version_compare( TC_fpu::$instance->version, ‘1.4’, ‘>’) ) ? ‘fpc_’ : ‘tc_fp_’;

    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);
    }
    add_filter($hook_prefix.’text_block’, ‘do_shortcode’);
    $hook_prefix = ( class_exists(‘TC_fpu’) && version_compare( TC_fpu::$instance->version, ‘1.4’, ‘>’) ) ? ‘fpc_’ : ‘tc_fp_’;

    add_filter($hook_prefix.’text_length’, ‘my_fp_text_length’); function my_fp_text_length(){     return 500; /*change this value to suit your needs*/ }

    This is the code all three as given above?

  • NaM

    Hi there,
    Thanks for all your incredible work 🙂
    However, that doesn’t work for me and breaks down my website when I try your code.
    I’ve got this error message on all pages of my website that don’t load anymore:
    “Parse error: syntax error, unexpected ‘global’ (T_GLOBAL) in path-to-my-child-theme/functions.php on line 155”
    Of course it’s about that line: “global $hook_prefix;”
    And my admin area isn’t accessible anymore when I leave your code, I’ve just got a blank page upon refresh.
    I’m using WordPress 3.9.1, developing with WampServer 2.4 – Apache 2.4.4 – PHP 5.4.12 – MySql 5.6.12
    Cheers 🙂

    • NaM

      Update

      I’ve realized, that whatever is the 1st line into a function, “it” doesnt like it for both of your functions: no_sanitize_text and my_fp_text_length and adpats the error on whatever the 1st line is (string, variable…).
      And now that I’ve put back everything same as your code above, it doesn’t like the line with “$option_prefix”.. Oo
      Any idea?

      • Rocco Aliberti Post author

        Hi NaM,
        are you sure you copied the code right? Looks like a syntax error. Something that could happen if you missed the opening brace after the function prototype. Anyway mind opening a new topic on the support forum ? You can paste here the code you have in your child-theme functions.php and report back the link there.
        Thanks.

  • loic leveque

    Hello Rocco,
    Do these codes apply to the post excerpts on the front page as well?

    All my best wishes,

    • Rocco Aliberti Post author

      Hi loic,
      nope. WordPress strips tags in the excerpt, for the same reasons. There are plug-ins to change that behavior, or you can use some code you can find on the net.
      Bests :).

  • Mike

    I think I must be missing something, having copied the code from the first section into my child functions.php file, the file become corrupted.

    • Rocco Aliberti Post author

      Hi Mike, what do you mean with corrupted?
      Just tested it again, I got no issues.
      Do you have WP_DEBUG set to true? Could be useful to know what kind of error you have in your child-theme functions.php .

    • Edyta

      Hello Rocco,
      Thanks for your reply.
      I dont know much about php so I was trying to past the code from your link to functions.php and play width some shortcodes but it didnt work.
      As you suggested I will start a new topic.
      Cheers

  • Edyta

    Hello,
    Great template, great tutorials! Thank you!
    Is it possible to do the same thing with the carousel caption, to have HTML entities or shortcodes?
    Many thanks!

    • Rocco Aliberti Post author

      Hello Edyta, at the moment the slider text block is not that flexible. If you have specific (small) needs we can try to find a solution. Please open a new topic in the support forum

Comments are closed.