• Resolved blueberry25

    (@blueberry25)


    Hello,
    I’m trying to add a shortcode that allows html entities (unordered list) in the slider’s text. I’ve past this code to the functions.php (found thanks to customizr forum):

    add_filter('tc_slide_text_length', 'my_tc_slide_text_length');
    function my_tc_slide_text_length(){
        return 500; /*change this value to suit your needs*/
    }
    add_filter('tc_slider_display', 'do_my_shortcode');
    function do_my_shortcode($html){
        return do_shortcode(html_entity_decode($html));
    }

    Then I was trying to figure out how to add the shortcode to the slider’s text without any success for now.
    Thanks a lot for help.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Hi @blueberry
    You can’t put html code in the slide description text.
    Using the code above you need additional code to achieve that.
    It’s quite an hack, but… whatever works, isn’t it? ??
    Our goal is to put something like html code in a shortcode and render it, right? So try adding this to your child-theme functions.php:

    add_shortcode('htmlify', 'do_html');
    function do_html($attr, $content){
        return str_replace(array('{','}'), array('<','>'), $content);
    }

    Then in the slide’s description box put something like this:

    [htmlify]{/p}{ul class="my_class"}{li}first{/li}{li}second{/li}{/ul}{p}[/htmlify]

    Those leading {/p} and trailing {p}, are there ’cause by default customizr wraps the slide’s description text in <p class="lead"> </p>. So to keep our html valid we close that <p clas="lead"> with </p> and open a new <p> before the end to match the dangling </p>. Is this understandable? (sorry for my english). You may want to have some text before and after the ul, then what you have to use in the description box is something like this:
    [htmlify]SOMETHING BEFORE{/p}{ul class="my_class"}{li}first{/li}{li}second{/li}{/ul}{p class="lead"}SOMETHING AFTER[/htmlify].

    Hope this helps

    Thread Starter blueberry25

    (@blueberry25)

    Hi d4z_c0nf,
    Thanks a lot for your help and the explanation!
    I literary copy/pasted your codes but it didn`t work…
    The slider is showing the text with the code.

    That’s what I have in my child-theme functions.php

    add_filter('tc_slide_text_length', 'my_tc_slide_text_length');
    function my_tc_slide_text_length(){
        return 500; /*change this value to suit your needs*/
    }
    add_filter('tc_slider_display', 'do_my_shortcode');
    function do_my_shortcode($html){
        return do_shortcode(html_entity_decode($html));
    }
    add_shortcode('htmlify', 'do_html');
    function do_html($attr, $content){
        return str_replace(array('{','}'), array('<','>'), $content);
    }

    That’s what I have in the slide description box (not the image caption/description box):

    [htmlify]{/p}{ul class="my_class"}{li}first{/li}{li}second{/li}{/ul}{p}[/htmlify]

    Is it the same you have?

    That’s the result -> https://i58.tinypic.com/akihx4.png

    Can you be more specific about “The slider is showing the text with the code.” you mean the whole shortcode [htmlify]....[/htmlify] or just {/p}{ul class="my_class"}{li}first{/li}{li}second{/li}{/ul}{p}
    ?

    Thread Starter blueberry25

    (@blueberry25)

    It works!!!

    Im sorry, I removed the second filter code while copy-pasting. Thats why it didn`t work.

    Many thanks!

    Perfect! You’re welcome ??
    Could you mark this topic as resolved?
    Thank you.

    Thread Starter blueberry25

    (@blueberry25)

    Done:)

    Neat! ?? Glad to have you back!

    Hehe, I have to make a snippet for this, and add instruction for use for it and that one for featured pages.
    Thanks ElectricFeet ??

    Hi there,

    I don’t know if I’m doing something really stupid, but when I try this, all of the code appears on the slider. So rather than just seeing the text, you can also see the [htmlify]{p} etc.

    I’ve copied and pasted the code (both filters and the shortcode) to my functions.php and have added the [htmlify] {p} and {br /} tags to my slider’s caption, so I’m not sure what I’m doing wrong ??

    Any suggestions?

    Hi jolieaparis,
    works fine here. Did you copy this whole code https://www.ads-software.com/support/topic/adding-shortcode-to-a-sliders-text?replies=10#post-5607868

    in your child-theme functions.php?

    Can I see the content of this file?
    Please copy the content in pastebin.com and then put the link here.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Adding shortcode to a slider`s text’ is closed to new replies.