Adding line break to slider caption description
-
Hi,
Is there a way to add a line break or “<p>” tag in the slider caption description?
Thanks
-
I have found a way to do that but i’m not sure if it’s the right way.
First of all, what we will get (just to be sure that’s what you need): You are going to specifie a number. e.g. 16. And the code is going to put a line break before or after the 16th character, it never brokes any word so if the 16th character is in the middle of a word the line break will be donne before this word. Let me tell you that it will be donne with all the descriptions in the slider.How to do that:
First of all we are going to edit the theme file /customizr/parts/class-content-slider.php.
Here you need to search that line (it should be line 80):$text = ( strlen($text) > $default_text_length ) ? substr( $text,0,strpos( $text, ' ' ,$default_text_length) ). ' ...' : $text;
and put this on the next line:
$text = nl2br(wordwrap($text, 16, "\r\n", true));
The 16 is the number you want to change to control the line break.
The wordwrap() puts a line breack on 16th character or before and the nl2br() changes it to an html line break.
Next you have to find this line in the same document (after the last change it would be line 201):$data['text'] = esc_html( apply_filters( 'tc_slide_text', $data['text'], $id ) );
Copy, paste it on the next line and coment it, so you will have somethig like it:
//$data['text'] = esc_html( apply_filters( 'tc_slide_text', $data['text'], $id ) ); $data['text'] = apply_filters( 'tc_slide_text', $data['text'], $id );
As you can see i modified the line so it respects the line break. I recomend to keep the old line comented so you can always undo the proces.
Let me know if you have any problem or that’s not the solution you was expecting.
I’m not a php expert, but that looks a neat solution!
Only comment would be to not make this change in the core file, but to take a copy of the class.php file and move it to a Child Theme.
Then your change will stay in place when the Theme is updated.
There are also lots of Hooks built in, so you should look to change this to code that is added to the CT functions.php in the similar form of the php snippets
I’m trying to learn at the moment so hopefully someone else will finalise this.
Thanks for your answer. It’s my first time with wordpress and didn’t know about child themes.
Thanks Galegri,
Your solution is generic for all slides. Is there a way to target only a specific slide in the slider?
I do not want to apply this pattern to all the slides.
The problem with that is the slides don’t use any id so you can’t distinct one of the other.
You should modify the way they are created to give them an id and then use a conditional to aply what i expose in my coment only on the slide you want.
Now, i don’t have time to do it for you, but i’m working on the slider too and i’m learning how it works. May be in two or three days, when i have my work donne, i’ll know enought to help you.
Thanks!
In the meantime, I will look into the code myself to try to figure it out.
If you find something in a few days let me know.
I hope the author will work on an easier way to achieve this directly in the theme.
I found another way to do it, specific to a slide
In the meta description of the slide, I add a \r\n tag. For example:
Double-sided Business Cards from $49,99 \r\n Business cards should be a conversation starter – something to be kept and acted on.
I create a child class-content-slider.php and locate this line:
$text = ( strlen($text) > $default_text_length ) ? substr( $text,0,strpos( $text, ' ' ,$default_text_length) ). ' ...' : $text
And add this line right after:
$text = str_replace('\r\n','<br/>',$text);
Next you have to find this line in the same document:
$data['text'] = esc_html( apply_filters( 'tc_slide_text', $data['text'], $id ) );
Copy, paste it on the next line and coment it, so you will have somethig like it:
//$data[‘text’] = esc_html( apply_filters( ‘tc_slide_text’, `$data[‘text’], $id ) );
$data[‘text’] = apply_filters( ‘tc_slide_text’, $data[‘text’], $id );`Hahahaa!
After all the wordwrap function was doing the same sooo… I don’t know how didn’t see it before, sorry.
Good job!Hi, is this resolved now? If yes can you set it as “resolved”?
Thanks!I am having the same problem, I need to add a line break and html code is not recognized. My limitation is that I cannot make edits to the template code/functions, because I am using the template in a hosted site.
Is this something you foresee adding to the template’s functionality?
I know that Nikeo is adding a separate class for each slide in the next release, so you will probably be able to hack it then with an
:after
pseudo element. Start a new thread if you need more once the new release is out (should be in max a couple of weeks).
- The topic ‘Adding line break to slider caption description’ is closed to new replies.