Blog index displaying extra content around Read More button

Hi X Theme:

Within my child theme, I added the following code found in the forum under functions.php:

// Custom 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 x-btn x-btn-regular x-btn-flat">' . __( 'Read More', '__x__' ) . '</a></div>';
    } else if ( $stack == 'renew' ) {
      return ' ... <a href="' . get_permalink() . '" class="more-link x-anchor x-anchor-button"><div class="x-anchor-content"><div class="x-anchor-text"><span class="x-anchor-text-primary">' . __( 'Read More', '__x__' ) . '</span></div></div></a>';
    } else if ( $stack == 'icon' ) {
      return ' +++';
    } else if ( $stack == 'ethos' ) {
      return ' +++';
    }}
  add_filter( 'excerpt_more', 'x_excerpt_string' );
endif;

The Read More button looks fine, but before/after the button is a little artifact that when explored is an additional “read more” link. I’m guessing it’s related to the x_after_the_excerpt_begin/ends hooks.

You can see this here: http://ccph.lisaburger.com/blog/
Be sure to scroll down to the 3rd/4th blog post to see what I’m talking about. It’s the black square/dot before and after the button.

I’ve looked pretty hard to find where the x_after_the_excerpt_ hooks are created and can’t find them. I can see where they are called in /framework/views/global/_content-the-excerpt.php.

Is there a way to clear what’s stored and outputted in there?

Hello @TechCoachLisaB,

Thanks for writing in! Do you have any other custom code or modifications added to your child theme? To better assist you with your issue, kindly provide us access to your site so that we can check your settings. Please create a secure note with the following info:
– Link to your site
– WordPress Admin username / password

To know how to create a secure note, please check this out: How The Forum Works

Best Regards.

Okay I think I see what the problem is, but not how to fix it or why it’s happening. Maybe another pair of eyes can help?

I decided to scrap that plan. Since I want a button for EVERY blog post on the blog-index I copied the code from /framework/views/renew/content.php into the child class and tweaked a little. After x_get_view(‘global’, ‘content’) is called I have what should be simple/boring html to create my button:

<a href="...notimportant" class="read-more">
   <div>
      <div>
         <span class="text-primary">Read More</span>
      <div>
   </div>
</a>

The issue is, when it’s being rendered on the browser it’s all goofy (see screenshot). I realize now this was the same issue I was having with my first attempt at it. Do you know what could be causing this?

Hello @TechCoachLisaB,

The excerpt is wrap with a <p> tag. You cannot nest a <div> tag inside it. That would be invalid and would result to an issue. You may use this code instead:

// Custom 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 class="more-link x-btn x-btn-regular" 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;

You may customize the button yet you MUST only use this:

<a href="#" class="read-more x-anchor x-anchor-button">
  <span class="x-anchor-content">
	  <span class="x-anchor-text">
		  <span class="x-anchor-text-primary">Read More</span>
	  </span>
  </span>
</a>

Home this explains your issue briefly.

Thanks. I actually realized before you went in there, that I had an unclosed div tag in the views/renew/content.php file. I am able to have divs there and have formatted the buttons the way I want. You’d think after 20 years I’d have caught that error faster, but ho hum.

But yes, I think had I used the function to update the filter, span tags would have been required.

You are most welcome!
If you need anything else we can help you with, don’t hesitate to open another thread.