Support » Themes and Templates » Remove "Continue reading" from excerpts

  • Hi,
    I’m trying to remove the “Continue reading” link from my site‘s excerpts.
    I’ve found a lot of filters on the internet but none of them have worked properly.

    I want the […] removed as well.

    Thanks 🙂

    makta112

Viewing 10 replies - 1 through 10 (of 10 total)
  • esmi

    (@esmi)

    Forum Moderator

    What theme are you using? Where did you download it from?

    Twenty Eleven. I downloaded it from WordPress.

    esmi

    (@esmi)

    Forum Moderator

    Do not edit the theme itself. First create a child theme for your changes.

    Michael

    (@alchymyth)

    Forum Moderator

    try to add this to functions.php of your child theme:

    add_action( 'after_setup_theme', 'twentyeleven_child_continue_reading_setup' );
    
    function twentyeleven_child_continue_reading_setup() {
    	remove_filter( 'get_the_excerpt', 'twentyeleven_custom_excerpt_more' );
    	remove_filter( 'excerpt_more', 'twentyeleven_auto_excerpt_more' );
    	add_filter( 'excerpt_more', 'twentyeleven_child_custom_excerpt_more' );
    }
    function twentyeleven_child_custom_excerpt_more( $more ) {
    	return '';
    }

    alchymyth

    That didn’t work. The site crashed when I used it.

    esmi

    (@esmi)

    Forum Moderator

    Are you using a child theme?

    Yes – I’m using a child theme for Twenty Eleven.

    esmi

    (@esmi)

    Forum Moderator

    What was the exact error? I cannot see any problem in the code above. Perhaps you introduced an error when you added it.

    The entire page went white when I added the code.

    Do I need to remove or replace some code in functions.php before adding this one?

    This is how my child theme’s functions.php looks like:

    <?php function twentyeleven_posted_on() {
    	printf( __( '<span class="sep"></span><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s" pubdate>%4$s</time></a> / <span class="by-author"><span class="sepp"><?php the_author(); ?></span><span class="author vcard"><a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a></span></span>', 'twentyeleven' ),
    		esc_url( get_permalink() ),
    		esc_attr( get_the_time() ),
    		esc_attr( get_the_date( 'c' ) ),
    		esc_html( get_the_date() ),
    		esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    		esc_attr( sprintf( __( 'View all posts by %s', 'twentyeleven' ), get_the_author() ) ),
    		get_the_author()
    	);
    }
    
    add_action( 'after_setup_theme', 'twentyeleven_child_continue_reading_setup' );
    
    function twentyeleven_child_continue_reading_setup() {
    remove_filter( 'get_the_excerpt', 'twentyeleven_custom_excerpt_more' );
    add_filter( 'get_the_excerpt', 'twentyeleven_child_custom_excerpt_more' );
    
    remove_filter( 'excerpt_more', 'twentyeleven_child_auto_excerpt_more' );
    add_filter( 'excerpt_more', 'twentyeleven_child_auto_excerpt_more' );
    }
    
    function twentyeleven_child_custom_excerpt_more($output ) {
            if ( is_search() && has_excerpt() && ! is_attachment() ) {
            //edited 'continue reading' for search results//
                    $output .= ' <a href="'. esc_url( get_permalink() ) . '">' . 'Search Results Continue Reading <span class="meta-nav">→</span>' . '</a>';
            }       elseif ( has_excerpt() && ! is_attachment() ) {
                    $output .= ' <a href="'. esc_url( get_permalink() ) . '">' . __( 'Continue reading <span class="meta-nav">→</span>', 'twentyeleven' ) . '</a>';
            }
            return $output;
    }
    
    function twentyeleven_child_auto_excerpt_more($output ) {
            //edited 'continue reading' for search results//
            if( is_search() ) { return ' …' . ' <a href="'. esc_url( get_permalink() ) . '">' . 'More...' . '</a>';
            } else { return ' …' . twentyeleven_continue_reading_link();
            }
    }
    
    // Replaces the excerpt "more" text by a link
    function new_excerpt_more($more) {
           global $post;
    	return '<a class="moretag" href="'. get_permalink($post->ID) . '"> Read the full article...</a>';
    }
    add_filter('excerpt_more', 'new_excerpt_more');
    
    // Get combined FB and WordPress comment count
    function full_comment_count() {
    global $post;
    $url = get_permalink($post->ID);  
    
    $filecontent = file_get_contents('https://graph.facebook.com/?ids=' . $url);
    $json = json_decode($filecontent);
    $count = $json->$url->comments;
    $wpCount = get_comments_number();
    $realCount = $count + $wpCount;
    if ($realCount == 0 || !isset($realCount)) {
        $realCount = 0;
    }
    return $realCount;
    }
    
    add_filter( 'comment_form_defaults', 'twentyelevenchild_modify_comment_fields' );
    
    function twentyelevenchild_modify_comment_fields( $fields ) {
    $user = wp_get_current_user();
    $user_identity = $user->exists() ? $user->display_name : '';
    $fields['logged_in_as'] = '<p class="logged-in-as">' . sprintf( __( 'Logged in as <b>%2$s</b>. <a href="%3$s" title="Log out of this account">Not you?</a>' ), admin_url( 'profile.php' ), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( ) ) ) ) . '</p>';
    $fields['must_log_in'] = '<p class="must-log-in">' . sprintf( __( 'You must be logged in to post a comment<br><div id="member"><a href="/wp-login.php" class="simplemodal-login">Login</a><a href="/wp-login.php?action=register" class="simplemodal-register">Register</a></div>' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>';
    return $fields;
    }
    
    add_filter('body_class', 'blacklist_body_class', 20, 2);
    function blacklist_body_class($wp_classes, $extra_classes) {
    if( is_single() || is_page() ) :
    // List of the classes to remove from the WP generated classes
    $blacklist = array('singular');
    // Filter the body classes
      foreach( $blacklist as $val ) {
        if (!in_array($val, $wp_classes)) : continue;
        else:
          foreach($wp_classes as $key => $value) {
          if ($value == $val) unset($wp_classes[$key]);
          }
        endif;
      }
    endif;   // Add the extra classes back untouched
    return array_merge($wp_classes, (array) $extra_classes);
    }
    
    show_admin_bar(false);
    
    function twentyeleven_content_nav( $nav_id ) {
    	global $wp_query;
    
    	if ( $wp_query->max_num_pages > 1 ) : ?>
    		<nav id="<?php echo $nav_id; ?>">
    			<h3 class="assistive-text"><?php _e( 'Post navigation', 'twentyeleven' ); ?></h3>
    			<?php wp_pagenavi(); ?>
    		</nav><!-- #nav-above -->
    	<?php endif;
    }
    
    add_filter( 'post_thumbnail_html', 'my_post_image_html', 10, 3 );
    
    function my_post_image_html( $html, $post_id, $post_image_id ) {
    
      $html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_the_title( $post_id ) ) . '">' . $html . '</a>';
      return $html;
    
    }
    esmi

    (@esmi)

    Forum Moderator

    Try checking your site’s error logs for a more specific error message. Your hosts should be able to help you accessing your site’s error logs.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Remove "Continue reading" from excerpts’ is closed to new replies.