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

    Askeam
    Participant

    Could you please advise on how to add “read more” after manual except within x-child-theme?

    This is a two part solution form WordPress.. but how will the second “remove filter” part look for x-theme?

    Thank you.

    #620234

    Christopher
    Moderator

    Hi there,

    Please add this in functions.php :

    // Excerpt More String
    // =============================================================================
    
    if ( ! function_exists( 'x_excerpt_string' ) ) :
      function x_excerpt_string( $more ) {
        
        $stack = x_get_stack();
    
        if ( $stack == 'integrity' ) {
          return ' ... <div><a href="' . get_permalink() . '" class="more-link">' . __( 'Read More', '__x__' ) . '</a></div>';
        } else if ( $stack == 'renew' ) {
          return ' ... <a href="' . get_permalink() . '" class="more-link">' . __( 'Read More', '__x__' ) . '</a>';
        } else if ( $stack == 'icon' ) {
          return ' ...';
        } else if ( $stack == 'ethos' ) {
           return ' ... <div><a href="' . get_permalink() . '" class="more-link">' . __( 'Read More', '__x__' ) . '</a></div>';
        }
    
      }
      add_filter( 'excerpt_more', 'x_excerpt_string' );
    endif;

    Hope it helps.

    #649294

    varunchugh
    Participant

    Hi, I followed the steps and pasted the above mentioned code to functions.php but this does not work for me. Please look at the first post on http://www.outlineofphotography.com

    Regards
    Varun

    #649420

    Rupok
    Member

    Hi Varun,

    Thanks for updating. Would you mind providing us with login credentials so we can take a closer look? To do this, you can make a post with the following info:

    – Link to your site
    – WordPress Admin username / password
    – FTP credentials

    Don’t forget to select Set as private reply. This ensures your information is only visible to our staff.

    #649446

    varunchugh
    Participant
    This reply has been marked as private.
    #649631

    Nabeel A
    Moderator

    Hi again,

    Thank you for the credentials, Please replace the previous code with this one in your child theme’s functions.php file:

    function custom_excerpt($text) {  // custom 'read more' link
       if (strpos($text, '[...]')) {
          $excerpt = strip_tags(str_replace('[...]', '... <a href="'.get_permalink().'">Read More...</a>', $text), "<a>");
       } else {
          $excerpt = '<p>' . $text . '<a href="'.get_permalink().'">Read More...</a></p>';
       }
       return $excerpt;
    }
    add_filter('the_excerpt', 'custom_excerpt');

    Let us know how this goes!

    #650504

    varunchugh
    Participant
    This reply has been marked as private.
    #650513

    varunchugh
    Participant
    This reply has been marked as private.
    #650545

    Thai
    Moderator

    Hi Varun,

    Try adding following CSS under Customize > Custom > CSS:

    .more-link {
    display: none;
    }

    Hope it helps ๐Ÿ™‚

    #650634

    varunchugh
    Participant

    Works, great! thanks a lot! Much appreciated.

    Regards
    Varun

    #650645

    Nico
    Moderator

    You’re most welcome.

    Feel free to ask us again. Have a great day! ๐Ÿ™‚

    #661728

    Ashley H
    Participant

    The second set of code above worked well for me! Is there anyway for the “Read More…” to display at the end of the text sentence? Also, can I make the font weight bolder so it’s easier to read?

    Thanks!!

    #661947

    Rue Nel
    Moderator

    Hi Ashley,

    Thanks for updating this thread!

    Please use this code instead:

    function custom_excerpt($text) {  // custom 'read more' link
       if (strpos($text, '[...]')) {
          $excerpt = strip_tags(str_replace('[...]', '... <a href="'.get_permalink().'">Read More...</a>', $text), "<a>");
       } else {
          $excerpt = '<p>' . strip_tags($text) . '<a class="read-more" href="'.get_permalink().'">Read More...</a></p>';
       }
       return $excerpt;
    }
    add_filter('the_excerpt', 'custom_excerpt');

    And if there is a need to change the colors of the read more text, you can insert this code in your child themeโ€™s style.css

    .site a.read-more {
      color: red;
    }
    
    .site a.read-more:hover {
      color: green;
    }

    Feel free to change the colors. We would loved to know if this has work for you. Thank you.