Adam Bell
Adam Bell

Reputation: 1045

WordPress: Remove get_the_title from my content template

I'm running a variation of the _underscores theme for my clients site and we already have the page or post title displayed in a custom header element, so it doesn't need to be inside of the loop anymore on template-parts/content.php. I thought just deleting 'get_the_title' would eliminate seeing the title in the body of my post, but instead, I just got a variety of errors like 'unexpected ')'' or similar. So how do I get rid of the get_the_title reference and still make this valid? Here's what I have currently.

<div class="entry-content">
    <?php if ( is_category() || is_archive() ) {
        the_excerpt('');
            } else {
        the_content( sprintf(
        wp_kses(
            /* translators: %s: Name of current post. Only visible to screen readers */
            __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'orchestra' ),
            array(
                'span' => array(
                    'class' => array(),
                ),
            )
        ),
        get_the_title()
    ) );

    if ( is_category() || is_archive() ) {
        echo '<p class="btn-cc"><a href="%s" rel="bookmark">Read More</a></p>';
    }

    wp_link_pages( array(
        'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'orchestra' ),
        'after'  => '</div>',
    ) );
    }
    ?>

Upvotes: 1

Views: 239

Answers (1)

Xhynk
Xhynk

Reputation: 13840

The formatting on this makes it relatively hard to read. So first I'd clean that up a bit. If you look at the documentation for the_content() you'll see that the first parameter is the $more_text_link. So lines 5 through 15 are adding a "Continue Reading [Post Title]" test.

If you don't need that at all, you can just use the_content() like so:

<div class="entry-content">
    <?php
        if( is_category() || is_archive() ){
            the_excerpt('');
        } else {
            the_content();

            if( is_category() || is_archive() ){
                echo '<p class="btn-cc"><a href="%s" rel="bookmark">Read More</a></p>';
            }

            wp_link_pages( array(
                'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'orchestra' ),
                'after'  => '</div>',
            ) );
        }
    ?>

Otherwise, you'll want to add in your own default text:

<div class="entry-content">
    <?php
        if( is_category() || is_archive() ){
            the_excerpt('');
        } else {
            the_content( 'Continue Reading' );

            if( is_category() || is_archive() ){
                echo '<p class="btn-cc"><a href="%s" rel="bookmark">Read More</a></p>';
            }

            wp_link_pages( array(
                'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'orchestra' ),
                'after'  => '</div>',
            ) );
        }
    ?>

Upvotes: 1

Related Questions