• Resolved studio481

    (@studio481)


    Hello,

    LOVE the Hemingway theme. I am using WordPress 5.1.1 running Hemingway Theme as a child theme. I have toggled For each article in a feed, show Summary (instead of Full Text) and I have excerpts created for my posts, however, they are all shown in full, unlike your demo which has excerpts with a nice Continue Reading button.

    Is there another toggle somewhere that I’ve missed? I tried using the original Hemingway theme instead of my child theme; no luck. Disabled all of the plugins; still no excerpts.

    Grateful for any advice.

    Kind Regards,
    Chris

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • On the demo they have that excerpt because they are using the More tag and it shows the Continue Reading button. If you want it to show just the excerpt you’ve created, go into your child theme’s content.php file and change the_content(); on line 93 over to the_excerpt();

    If you want to include the Continue Reading button as well you can add the following code to your functions.php file inside of your child theme

    function wpsupport_excerpt_more( $more ) {
        if ( ! is_single() ) {
            $more = sprintf( '<p><a class="more-link" href="%1$s">%2$s</a></p>',
                get_permalink( get_the_ID() ),
                __( 'Continue Reading', 'textdomain' )
            );
        }
     
        return $more;
    }
    add_filter( 'excerpt_more', 'wpsupport_excerpt_more' );
    Thread Starter studio481

    (@studio481)

    Thank you Jarret!

    The change to the parent theme’s content.php did force the excerpt. Bravo!

    However, the code for the child theme’s function.php did not result in the Continue Reading button.

    Is there another step needed? I have a few other code snippets in my function.php file. Not sure if that would affect the code you suggested. Posting my function.php code below in case it is useful for troubleshooting. Thank you again for you assistance!

    <?php
    add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
    function my_theme_enqueue_styles() {
     
        $parent_style = 'hemingway_style'; 
     
        wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
        wp_enqueue_style( 'child-style',
            get_stylesheet_directory_uri() . '/style.css',
            array( $parent_style ),
            wp_get_theme()->get('Version')
        );
    }
    
    // Redirect Registration Page
    function my_registration_page_redirect()
    {
        global $pagenow;
     
        if ( ( strtolower($pagenow) == 'wp-login.php') && ( strtolower( $_GET['action']) == 'register' ) ) {
            wp_redirect( home_url('/registration'));
        }
    }
     
    add_filter( 'init', 'my_registration_page_redirect' );
    
    /**
    * Format WordPress User's "Display Name" to Full Name on Login
    * ------------------------------------------------------------------------------
    */
    
    add_action( 'wp_login', 'wpse_9326315_format_user_display_name_on_login' );
    
    function wpse_9326315_format_user_display_name_on_login( $username ) {
        $user = get_user_by( 'login', $username );
    
        $first_name = get_user_meta( $user->ID, 'first_name', true );
        $last_name = get_user_meta( $user->ID, 'last_name', true );
    
        $full_name = trim( $first_name . ' ' . $last_name );
    
        if ( ! empty( $full_name ) && ( $user->data->display_name != $full_name ) ) {
            $userdata = array(
                'ID' => $user->ID,
                'display_name' => $full_name,
            );
    
            wp_update_user( $userdata );
        }
    }
    
    function wpsupport_excerpt_more( $more ) {
        if ( ! is_single() ) {
            $more = sprintf( '<p><a class="more-link" href="%1$s">%2$s</a></p>',
                get_permalink( get_the_ID() ),
                __( 'Continue Reading', 'textdomain' )
            );
        }
     
        return $more;
    }
    add_filter( 'excerpt_more', 'wpsupport_excerpt_more' );
    
    ?>
    • This reply was modified 5 years, 12 months ago by studio481.

    Hmmm, not quite sure….maybe because you have the excerpt already created instead of just letting it choose whatever content it would normally pick? If you remove the excerpt for one of your posts just to test, does it then show the Continue Reading button for that post on the index page?

    Additionally, the change to content.php should be done in your child theme and not in the parent theme. You’ll want to copy over content.php from the parent theme into your child theme and make the updates there. That way, if the parent theme is updated it won’t overwrite your customizations.

    Thread Starter studio481

    (@studio481)

    Jarret,

    Thank you again for your assistance. So I copied content.php over to the child theme and restored the original to the_content(); on line 93.

    I also removed all content from the excerpt field on the latest post and sure enough, it choose the first 312 characters and put a Continue Reading button. Good clue, but not preferred. Not sure why I am not about to use the Excerpt as a teaser with a button, as is typical.

    Do you think this behavior is deliberated coded into the functions.php of the parent theme? I perused it and could find no occurrence of the word excerpt. But I did find this block of code starting at line 271. But not being a PHP programmer myself, I am not sure it is the source of the trouble.

    /* ---------------------------------------------------------------------------------------------
       CUSTOM MORE LINK TEXT
       --------------------------------------------------------------------------------------------- */
    
    if ( ! function_exists( 'hemingway_custom_more_link' ) ) {
    
    	function hemingway_custom_more_link( $more_link, $more_link_text ) {
    		return str_replace( $more_link_text, __( 'Continue reading', 'hemingway' ), $more_link );
    	}
    	add_filter( 'the_content_more_link', 'hemingway_custom_more_link', 10, 2 );
    
    }

    That code deals with using the <!–more–> tag in WordPress to “break up” parts of the post so that the theme should only show the content above that tag and then you have to visit the post page itself to see the rest. Similar to the excerpt feature except the excerpt can have completely different text to show versus the more tag will display the exact content in the post.

    Try adding the following after <?php the_excerpt(); ?> on line 93

    <p><a class="more-link" href="<?php echo the_permalink(); ?>">Continue Reading</a></p>

    So that the section looks like this

    <div class="post-content">
    			
    			<?php the_excerpt(); ?>
    
    			<p><a class="more-link" href="<?php echo the_permalink(); ?>">Continue Reading</a></p>
    						
    			<?php wp_link_pages(); ?>
    
    		</div><!-- .post-content -->

    I think that’ll get you what you want. You’ll just have to make sure that all of your posts have an excerpt defined otherwise nothing will show up other than the title

    Thread Starter studio481

    (@studio481)

    Thank you, Jarret! That worked! I really appreciate your assistance!

    • This reply was modified 5 years, 12 months ago by studio481.

    Is this functionality going to be added into the theme? I’d rather not make my own changes to theme only to have them undone when the theme is later updated to a new version.

    Hello
    i’m using wordpress-4.8.1 and excerpt is not working in any theme..even not working in demo post

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Excerpt Not Working’ is closed to new replies.