-
AuthorPosts
-
April 20, 2021 at 11:46 am #1295508
Hi There
I’m using the accordion elemen as a read more tab. Is it possible to change the text when active? I have set the title as ‘Read more’ and would like it to change to ‘Read less’ when active.
Cheers JaneApril 22, 2021 at 6:31 am #1295933Hey Byrne,
Thank you for the inquiry.
That should be possible with a little script in the functions.php file.
// a custom script // toggle accordion's read more text function ava_custom_script_mod_read_less() { if ( wp_script_is( 'avia-default', 'registered' ) ) { wp_add_inline_script( 'avia-default', ' (function($) { $(document).ready(function() { $(".toggler").each(function() { var active = $(this).is(".activeTitle"); if(active) { $(this).text("Read Less"); } }); $(".toggler").on("click", function(e) { e.preventDefault(); var active = $(this).is(".activeTitle"); var content = $(this).html(); var innerText = $(this).text().trim(); var new_content = content.replace(innerText, active ? "Read More" : "Read Less"); $(this).html(new_content); }); }); })(jQuery); '); } } add_action( 'wp_enqueue_scripts', 'ava_custom_script_mod_read_less', 9999);
Best regards,
IsmaelMay 23, 2021 at 4:52 pm #1301844hi ismael,
i was searching the same. your code works fine.
but the plus and minus (toggle icons) disapear with your code.
May 25, 2021 at 8:06 pm #1302284Hi,
@volmering: Where can we see the issue? Please post the site or page URL in the private field.Best regards,
IsmaelMay 25, 2021 at 8:51 pm #1302288thanks ismael
May 31, 2021 at 5:05 am #1303054Hi,
Sorry for the delay. We updated the code above. It should now include the + and – symbols and update them accordingly.
Best regards,
IsmaelMay 31, 2021 at 6:55 am #1303078no problem ismael, i know you guys have a lot to do.
the code works fine.
i just have to change:
var new_content = content.replace(innerText, active ? “Read More” : “Read Less”);
into
var new_content = content.replace(innerText, active ? “Read Less” : “Read More”);
:-)
June 1, 2021 at 10:15 am #1303371 -
AuthorPosts
- You must be logged in to reply to this topic.