Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

369
Views
Read More functionality code is not working as expected

I have a problem with the "read more" functionality I have implemented into my website. The code is working fine but only after two times of pressing the read more button created with the code. This code works when it detects the Wordpress read more tag on the text field in the backend and splits the text into two parts.

enter image description here

I'll paste a video of the problem here: https://vimeo.com/732701370

You can see also the problem in a page of my website like this one: https://mallorca-select.com/properties-for-sale/villa-project-in-ibiza/

I think that the code is working fine but there is only something that at first it makes the read more to not fold. If anyone can point me in the right direction would be awesome. Thank you

PHP CODE:

<?php 
    if(get_field('property_description')){
        $highlights = get_field('property_description');
        if(strpos($highlights, '<!--more-->') !== false) {
            $start = strstr($highlights, '<!--more-->', true);
            $end = strstr($highlights, '<!--more-->');
            echo "<div class='exsec'>".$start."</div>";
            echo "<div class='fullsec'>".$end."</div><div class='btnRM'><a href=''>READ MORE</a></div>";
        } else {
            echo $highlights;
        }
}?>

JAVASCRIPT CODE:

jQuery('.btnRM a').click(function(e){
    e.preventDefault();
    if(jQuery(this).text()=="READ MORE"){
        jQuery(this).parent().prev('.fullsec').fadeIn();    
        jQuery(this).text('LESS');
    } else {
        jQuery(this).parent().prev('.fullsec').fadeOut();
        jQuery(this).text('READ MORE'); 
    }
    
});
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Based on your video, I see that the hidden text was already shown. So first click at READ MORE button will do nothing and no fade in because the content was already shown (except text changed to LESS). jQuery fadeIn() does not do anything if the element was already shown and the same for fadeOut() for hidden element.

If you want the content hidden at first, update the div element with this <div class='fullsec' style='display: none;'> inside your PHP code. The Javascript code is fine.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!