Is there a has_more_tag() method or equivalent?

I need to determine if the current post has a “more” tag. I’m currently using

$pos=strpos($post->post_content, '<!--more-->');

Am I missing a built in method similar to has_excerpt()?

Related posts

Leave a Reply

4 comments

  1. Making a quick note of the codes we could use to show the_content(); if the More tag exists, and the_excerpt(); if it doesn’t.

    Code #1 (Recommended)

    <?php
        if( strpos( $post->post_content, '<!--more-->' ) ) {
            the_content();
        }
        else {
            the_excerpt();
        }
    ?>
    

    (Credit: MichaelH)

    Code #2

    <?php
        if( strpos( get_the_content(), 'more-link' ) === false ) {
            the_excerpt();
        }
        else {
            the_content();
        }
    ?>
    

    (Credit: Michael) Basically does #1 the other way around.

    Code #3

    <?php
        if( preg_match( '/<!--more(.*?)?-->/', $post->post_content ) ) {
            the_content();
        }
        else {
            the_excerpt();
        }
    ?>
    

    (Credit: helgatheviking) For use only in edge cases where you cannot use strpos(). Generally strpos() is more efficient than preg_match().


    Making it more conditional:

    <?php
        if ( is_home() || is_archive() || is_search() ) {
            if( strpos( $post->post_content, '<!--more-->' ) ) {
                the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) );
            }
            else {
                the_excerpt();
            }
        }
        else {
            the_content();
        }
    ?>
    

    What does it do? If the page shown is home, archive or search results page, then show the_content(); if the More tag exists, the_excerpt(); if it doesn’t, and simply show the_excerpt(); on all other pages.

  2. I could not get any of the provided solution to work, however I found this to be working well for me, publishing it as an extra solution if anybody else had problems getting it working. Just testing if the content is them same with and without stripping the teaser.

            // Choose the manual excerpt if exists
            if ( has_excerpt() ) :
                    the_excerpt();
    
            // Is there a more tag? Then use the teaser. ()
            elseif ( get_the_content('', false) != get_the_content('', true)  ) :
                global $more; 
                $more = 0;
                echo strip_tags(get_the_content( '', false ));
                $more = 1;
    
            // Otherwise make an automatic excerpt
            else :
                the_excerpt(40);
    
            endif;