'Read more' on excerpt within paragraph tags

Hi,

I’ve seen various posts on how to create and manipulate the excerpt via functions.php etc

However, I would like to add my ‘read more’ link right at the end of the excerpt on the posts page, so that it appears in-line. Looking at the source, the excerpt is wrapped in a paragraph, which closes before the ‘Read More’ link comes in. Is it possible to move the link inside the paragraph?

So, rather than:

<p>Maecenas faucibus mollis interdum.</p> <a href="#">Read More...</a>

It would be:

<p>Maecenas faucibus mollis interdum. <a href="#">Read More...</a></p>

Thanks

Geoff

Hello Geoff,

Thank you for the very detailed post information.

By default, we use this code:

// 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 ' ...';
    }

  }
  add_filter( 'excerpt_more', 'x_excerpt_string' );
endif;

Each of the stacks used different structure in displaying the read more in the post excerpts. May I know the URL of your site or which stack you are using?

Regards.

Hi RueNel,

Thank you for your quick reply. I’ve added a secure note with some more info.

Thanks

Geoff

Hello Geoff,

Thanks for the imformation.

Because what you are trying to accomplish requires a template customization, we would highly to suggest that you use a child theme. This allows you to make code changes that won’t be overwritten when an X update is released.

After the child theme is set up, please add the following code in your child theme’s functions.php file

// Custom Excerpt More String for Integrity
// =============================================================================

if ( ! function_exists( 'x_excerpt_string' ) ) :
  function x_excerpt_string( $more ) {

    $stack = x_get_stack();

    if ( $stack == 'integrity' ) {
      return ' ...<a href="' . get_permalink() . '" class="more-link">' . __( 'Read More', '__x__' ) . '</a>';
    } 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 ' ...';
    }

  }
  add_filter( 'excerpt_more', 'x_excerpt_string' );
endif;

Please let us know if this works out for you.

That’s perfect - thank you once again, Rue. Brilliant support as ever!

Geoff

You’re welcome, Geoff. Glad we’re able to help.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.