Site logo

Archived topic

Is there a way to change the automatic "..." to "[...]" in GP

12 replies · Started by sdanbu on May 6, 2017

Viewing posts 1–13 of 13

All post excerpts are changed to show "..." when the excerpt is cut off. It looks funny because the author did not write ...

Is there a way to change the automatic "..." to "[...]"?

Hi Scott,

This function should work:

add_action( 'after_setup_theme','tu_remove_read_more' );
function tu_remove_read_more() {
    remove_filter( 'excerpt_more', 'generate_blog_excerpt_more', 99 );
}

add_filter( 'excerpt_more', 'tu_blog_excerpt_more', 99 );
function tu_blog_excerpt_more( $more ) {
    if ( ! function_exists( 'generate_blog_get_defaults' ) )
        return;

    $generate_settings = wp_parse_args( 
        get_option( 'generate_blog_settings', array() ), 
        generate_blog_get_defaults() 
    );
	
    // If empty, return
    if ( '' == $generate_settings['read_more'] )
        return;
		
    return ' [...] <a title="' . esc_attr( get_the_title() ) . '" class="read-more" href="'. esc_url( get_permalink( get_the_ID() ) ) . '">' . $generate_settings['read_more'] . '</a>';
}

Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets

If you don't have anything entered in Customizer > Blog > Blog Content > Read more label, then try inserting a space.

Let me know.

I tried this it didn't work maybe i did something wrong

I downloaded and installed code snippets plugin

Then I added a new snipped and copied the above (see below)

add_action( 'after_setup_theme','tu_remove_read_more' );
function tu_remove_read_more() {
remove_filter( 'excerpt_more', 'generate_blog_excerpt_more', 99 );
}

add_filter( 'excerpt_more', 'tu_blog_excerpt_more', 99 );
function tu_blog_excerpt_more( $more ) {
if ( ! function_exists( 'generate_blog_get_defaults' ) )
return;

$generate_settings = wp_parse_args(
get_option( 'generate_blog_settings', array() ),
generate_blog_get_defaults()
);

// If empty, return
if ( '' == $generate_settings['read_more'] )
return;

return ' [...] ' . $generate_settings['read_more'] . '';
}

It didn't work - nothing changed. Is it because I should do something with my show posts lists?

After that, I also went to customizer to see blog>blog content>readmore and added a space but nothing changed either.

You could actually simplify it quite a bit now:

add_filter( 'generate_excerpt_more_output','tu_change_read_more' );
function tu_change_read_more() {
    return sprintf( ' [...] <a title="%1$s" class="read-more" href="%2$s">Read more</a>',
        the_title_attribute( 'echo=0' ),
        esc_url( get_permalink( get_the_ID() ) )
    );
}

Make sure the code snippet you added is actually activated as well.

I tried creating a snippet and activated it but it still didn't work.

I tried both snippets including the most recent one:
add_filter( 'generate_excerpt_more_output','tu_change_read_more' );
function tu_change_read_more() {
return sprintf( ' [...] Read more',
the_title_attribute( 'echo=0' ),
esc_url( get_permalink( get_the_ID() ) )
);
}

Do I need to edit function.php?

What version of GP are you using?

Can you show me a screenshot of the code snippet page?

Any chance you can show me the full page?

sent thanks

Ahh you're using WP Show Posts.

Try this instead:

add_filter( 'wpsp_ellipses','tu_wpsp_ellipses' );
function tu_wpsp_ellipses() {
    return '[...]';
}

wizardry

This archived topic is closed to new replies.