1

I am using WordPress 4.9 and in my content.php file I have the following code

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <?php do_action( 'spacious_before_post_content' ); ?>

    <?php 
    if( !is_single() ) {
    ?>
    <header class="entry-header">
    <h1 class="entry-title">
        <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute();?>"><?php the_title(); ?></a>
    </h1><!-- .entry-title -->
    </header>
    <?php
    }
    ?>

    <?php
        if( has_post_thumbnail() ) {
            if( of_get_option( 'spacious_site_layout', 'box_1218px' ) == 'box_1218px' || of_get_option( 'spacious_site_layout', 'box_1218px' ) == 'wide_1218px' ) {
                $featured = 'featured-blog-large'; 
            }
            elseif( of_get_option( 'spacious_site_layout', 'box_1218px' ) == 'box_978px' || of_get_option( 'spacious_site_layout', 'box_1218px' ) == 'wide_978px' ) {
                $featured = 'featured';
            }
            $image = '';                    
            $title_attribute = get_the_title( $post->ID );
            $image .= '<figure class="post-featured-image">';
            $image .= '<a href="' . get_permalink() . '" title="'.the_title( '', '', false ).'">';
            $image .= get_the_post_thumbnail( $post->ID, $featured, array( 'title' => esc_attr( $title_attribute ), 'alt' => esc_attr( $title_attribute ) ) ).'</a>';
            $image .= '</figure>';

            echo $image;
        }
    ?>
/////////////////////////////////
// The excerpt should be here.
/////////////////////////////////
    <div class="entry-content clearfix">        
        <?php
                the_excerpt();
        ?>
    </div>

This is basically the code from the spacious theme, but a some point the excerpts stopped to show. Using the_content() instead still gives the full content of the post perfectly. Since I am rather new to WordPress I have trouble identifying possible sources of the problem.

Moreover, in /inc/functions.php I have the following code that effect the excerpt.

add_filter( 'excerpt_length', 'spacious_excerpt_length' );
/**
 * Sets the post excerpt length to 40 words.
 *
 * function tied to the excerpt_length filter hook.
 *
 * @uses filter excerpt_length
 */
function spacious_excerpt_length( $length ) {
    return 40;
}

add_filter( 'excerpt_more', 'spacious_continue_reading' );
/**
 * Returns a "Continue Reading" link for excerpts
 */
function spacious_continue_reading() {
    return '';
}
1

Does the_excerpt() work if you remove the custom functions you have?

Firstly, for sanities sake to make sure the excerpt has a value, could you try replacing your current excerpt call with this?

<?php echo get_post_field('post_excerpt', $post->ID); ?>

If it does work then the problem is most likely related to your custom functions.

4
  • In fact that shows the excerpt now if the excerpt is the manually in the post editor. But the_excerpt should generate the excerpt automatically on the fly, right? With custom functions you mean the things in functions.php? What wonders me is that I did not change something in this files. Could it also be due to some plugin?
    – Jarno
    Nov 23 '17 at 8:25
  • Yes the_excerpt should work but it can get broken by many things, including not being called in the correct place (outside of the loop), custom functions (the things you've added to WordPress in your functions.php file and plugins. My advice would be to remove those functions and see if that fixes it, then add them back in one by one and if it stops working when you add one in then you know that's causing the issue. After that, go through your plugins and do the same. Nov 23 '17 at 8:58
  • Curiously the bug was fixed after updating all the plugins.
    – Jarno
    Nov 23 '17 at 23:43
  • Hmm, it must have been a conflicting plugin causing the issues! I'm glad it's working now :) Nov 27 '17 at 9:04

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.