Navigation
This is archived content. Visit our new forum.
  • Author
    Posts
  • #257090

    Rue Nel
    Moderator

    Hello There,

    Could you try another approach by using this custom excerpt function.

    // =============================================================================
    // Custom Excerpt Length - Call: echo excerpt($length);
    // =============================================================================
    
    function limit_excerpt($limit) {
       $excerpt = explode(' ', get_the_excerpt(), $limit);
       if (count($excerpt)>=$limit) {
          array_pop($excerpt);
          $excerpt = implode(" ",$excerpt).'.';
       } else {
          $excerpt = implode(" ",$excerpt);
       } 
       return $excerpt;
    }

    And you use it in your custom recent shortcode by replacing this code:

    
    $enable_excerpt ? '<span class="x-recent-posts-excerpt">' . strip_tags( get_the_excerpt() ) . '</span>' : ''; 

    With this code

    
    $enable_excerpt ? '<span class="x-recent-posts-excerpt">' .  strip_tags( limit_excerpt(30) )  . '</span>' : '';

    Please let us know how it goes.

    #257731

    Shark Bite
    Participant

    It seems like the link I shared worked in my function.php, still, I think I might have figured it out that the “Read More” css style not showing up might have something to do with that .x-recent-posts a class overwriting the .more-link class.

    However, I think it’s best to somehow edit the code in function.php. I tried to do that but I didn’t have any success….

    #257735

    Shark Bite
    Participant

    Oh sorry, I didn’t see the last message from 7:58pm. The link I shared works. It’s just that the css style for “Read More” isn’t showing up….

    #258002

    John Ezra
    Member

    Hi there,

    Thanks for updating the thread! You can add this under Custom > CSS in the Customizer or in your child theme’s style.css file.

    .readm {
        color:#F15A24;
    }
    
    .readm:hover {
        color:#000000;
        cursor: pointer;
    }

    You can add this under Custom > JavaScript in the Customizer.

    jQuery ( function( $ ) { 
    
    $(document).ready(function() {    
        $(".x-recent-posts.cf.vertical span").each ( function() {
             $( this ).html( $( this ).text().replace(/\Read More/g,'<span class="readm">Read More</span>'));
        
        } );
       
    });
    
    } );

    Hope this helps – thanks!

    #259676

    Shark Bite
    Participant

    That didn’t work. So I tried to edit the function.php again and I succeed. What I did was to edit the return to ”.

    // Excerpt More String
    // =============================================================================
    
    if ( ! function_exists( 'x_excerpt_string' ) ) :
      function x_excerpt_string( $more ) {
        
        $stack = x_get_stack();
    
        if ( $stack == 'integrity' ) {
          return '';
        } else if ( $stack == 'renew' ) {
          return '';
        } else if ( $stack == 'icon' ) {
          return ' ...';
        } else if ( $stack == 'ethos' ) {
          return ' ...';
        }
    
      }
      add_filter( 'excerpt_more', 'x_excerpt_string' );
    endif;
    
    // Content More String
    // =============================================================================
    
    if ( ! function_exists( 'x_content_string' ) ) :
      function x_content_string( $more ) {
    
        return '';
    
      }
      add_filter( 'the_content_more_link', 'x_content_string' );
    endif;

    and then edited the .excerpt to show
    . ( $enable_excerpt ? '<span class="x-recent-posts-excerpt">' . strip_tags( get_the_excerpt() ) . '</span>' . '&nbsp;' . '<span class="more-link">' . __( 'Read More', '__x__' ) . '</span>' : '' )

    As you can see, it works now. Thank you for all your help too.

    #259770

    Thai
    Moderator

    Glad you’ve sorted it out. You’re most welcome.