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”
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
}
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.
Can you give the sample of excerpt and the desired output so that I can understand it better?
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!
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
Yes that’s correct! Your code works great, thanks for the help 🙂
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.
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;”
I have the same problem with the global $hook_prefix;
I think it not possible to use global under a function.
Any solution?
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?
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 🙂
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?
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.
Hello Rocco,
Do these codes apply to the post excerpts on the front page as well?
All my best wishes,
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 :).
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.
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 .
Sorry Edyta, I was terribly wrong (sorry @Nicolas :P), though you still cannot put html entities in the slider description (at the moment), you can easily (if I’m not wrong again ;)) have shortocodes in it. So basically you can have whatever html code there :D.
A new snippet will be available soon, for the moment look here:
http://wordpress.org/support/topic/adding-shortcode-to-a-slider-1
Hello Rocco,
Thanks for your reply.
I don`t 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 didn`t work.
As you suggested I will start a new topic.
Cheers
Hi Edyta, cannot say why it doesn’t work for you. I have tested slider shortcodes just with contact-form7 (see the pic: http://oi61.tinypic.com/2u60o52.jpg) and a personal shortcode which prints a div with just a string inside, and it works. I wait for your topic in the wordpress support forum in order to understand what kind of issues you have with that code.
The problem is I don`t know how php / shortcodes works. I was also trying with the contact form and it worked indeed. Then I was trying to test an unordered list, putting it between different opening and closing shortcodes in the slider:
Coffee
Tea
Milk
And obviously I don`t know how:(
PS
Sorry for the text in red, my mistake.
Hi Edyta, sorry for the late reply.
You may find this useful.. (but maybe you’re blueberry25 ?)
http://wordpress.org/support/topic/adding-shortcode-to-a-sliders-text
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!
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