0

I have a problem.

It is <?php the_excerpt(); ?> empty from gutemberg <?php the_excerpt(); ?> pull little part of content from post but first next <?php the_permalink(); ?> under is broken and changed path from single blog to root of list of blog posts.

How to fix that?

E.g of the loop:

<?php
                  $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
                  $args = array(
                      'post_type' => 'post',
                      'posts_per_page' => 5,
                      'paged' => $paged
                  );
                  
                  $post_query = new WP_Query($args);
                  
                  if($post_query->have_posts() ) {
                      while($post_query->have_posts() ) {
                          $post_query->the_post();
                          $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'blog-thumb'); 
                          ?>
                          
               <div class="blog-item">
                  <?php if($featured_img_url) { ?>
                  <a href="<?php the_permalink(); ?>"><img src="<?php echo $featured_img_url; ?>" class="blog-thumb" id="img" alt=""></a>
                  <?php } ?>
                  <a href="<?php the_permalink(); ?>">
                     <h2 class="blog-title"><?php the_title(); ?></h2>
                  </a>
                  <?php the_excerpt(); ?>
                  <a href="<?php the_permalink(); ?> // broken link return to url.com/blog not url.com/single-blog-url" class="blog-btn">Read more</a>
               </div>
               <?php
                  }
                  }
                  ?> 
1
  • Are you filtering the excerpt, e.g. via the the_excerpt hook? If so, try disabling that filter and see if it helps. – Sally CJ Oct 16 '20 at 14:47
0

If it only breaks when the excerpt is empty, then I would check for the excerpt before outputting it.

<?php if ( ! empty( get_the_excerpt() ) : ?> // test for the excerpt

   <?php echo esc_html( get_the_excerpt() ); ?> // escape the excerpt in case there is html added

<?php endif; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.