WordPress.org

Ready to get started?Download WordPress

Forums

The Bootstrap
[resolved] Removing the excerpt "continue reading" link (9 posts)

  1. philipjohn
    Member
    Posted 1 year ago #

    Hiya,

    I'm using a page template in my Bootstrap child theme to display a list of custom posts with an excerpt. Each excerpt has the "continue reading" link on, which I'd like to remove.

    Having look in the parent functions.php it tells me to simply remove the two filters (hooking into excerpt_more and get_the_excerpt) to get rid of this.

    So, in my child functions.php I have the following;

    remove_filter( 'get_the_excerpt', 'the_bootstrap_custom_excerpt_more' );
    remove_filter( 'excerpt_more', 'the_bootstrap_auto_excerpt_more' );

    However, the "continue reading" link remains. I have tried adding the priority parameter, using 10, 1, 11 and 20 as values but that made no difference.

    Commenting out the add_filter() calls in the parent functions.php appears to be the only way to get the link to go away.

    This is one of those "I can't understand why it won't work!" scenarios so I'm guessing the solution is starring me in the face...any help opening my eyes is appreciated!

  2. FranceImage
    Member
    Posted 1 year ago #

    Hello,

    your child theme functions.php is loaded first, so you can't undo things that have not been done yet :)

    you have to use 'after_setup_theme' hook

    function undo_filters() {
    ...
    }
    
    add_action( 'after_setup_theme', 'undo_filters' );

    some good reading:

    Cheers

  3. philipjohn
    Member
    Posted 1 year ago #

    Told ya - staring me in the face! Thanks :)

  4. jmjf
    Member
    Posted 1 year ago #

    So, I'm trying to remove the Continue Reading link too. I put this in my child theme's functions.php and I'm still getting a Continue Reading link. Did I miss something here? Thanks.

    function remove_excerpt_more_link() {
    	remove_filter( 'get_the_excerpt', 'the_bootstrap_custom_excerpt_more' );
    	remove_filter( 'excerpt_more', 'the_bootstrap_auto_excerpt_more' );
    }
    
    add_action( 'after_setup_theme', 'remove_excerpt_more_link' );
  5. philipjohn
    Member
    Posted 1 year ago #

    @jmjf Silly question but, you've definitely activated your child and not bootstrap, yes?

  6. jmjf
    Member
    Posted 1 year ago #

    Yep. It's definitely my child theme (looks very different from Bootstrap default). I guess one question might be: how should I be pulling the excerpt? I'm using the_excerpt() because that's what's in the default partials/content.php. Should I be using one of the other excerpt options?

  7. @vit
    Member
    Posted 1 year ago #

    my clear way:

    function hwlab_excerpt_txt() {
    	remove_filter( 'get_the_excerpt', 'the_bootstrap_custom_excerpt_more' );
    	the_excerpt_rss();
    }

    it work fine fore me.

  8. jmjf
    Member
    Posted 1 year ago #

    As I was experimenting last night, I found that get_the_excerpt will attempt to put the link in (even if I remove filter), and if the excerpt is short, that can mess up the HTML. I modified an example function from codex to grab the post's excerpt text directly rather than use functions. If there is no excerpt, grab the first chunk of the article with a little extra. Then whack it down to the desired length, always terminating on a whole word.

    function the_excerpt_max_charlength($charlength) {
    	$post = get_post();
    	$excerpt = $post->post_excerpt;
    	$charlength++;
    
    	if (mb_strlen($excerpt) == 0) $excerpt = mb_substr($post->post_content, 0, $charlength + 5);
    
    	if ( mb_strlen( $excerpt ) > $charlength ) {
    		$subex = mb_substr( $excerpt, 0, $charlength - 5);
    		$exwords = explode( ' ', $subex );
    		$excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
    		if ( $excut < 0 ) {
    			echo mb_substr( $subex, 0, $excut );
    		} else {
    			echo $subex;
    		}
    	} else {
    		echo $excerpt;
    	}
    	echo ' [. . .]';
    }
  9. Clark
    Member
    Posted 1 year ago #

    FranceImage's suggestion above worked perfectly for me, thank you!

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic

Tags

No tags yet.