Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #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 Jane

    #1295933

    Hey 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,
    Ismael

    #1301844

    hi ismael,

    i was searching the same. your code works fine.

    but the plus and minus (toggle icons) disapear with your code.

    #1302284

    Hi,


    @volmering
    : Where can we see the issue? Please post the site or page URL in the private field.

    Best regards,
    Ismael

    #1302288

    thanks ismael

    #1303054

    Hi,

    Sorry for the delay. We updated the code above. It should now include the + and – symbols and update them accordingly.

    Best regards,
    Ismael

    #1303078

    no 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”);

    :-)

    #1303371

    Hi,

    Thank you for the info. Glad to know it is working. Please feel free to open another thread if you need anything else.

    Have a nice day.

    Best regards,
    Ismael

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.