2

I've tried to remove the meta-nav arrow from end of my "Read more".

I'm building a child theme on top of Twenty Fourteen and have used

// Change excerpt length
    function new_excerpt_length( $length ) {
    return 20;
}
add_filter( 'excerpt_length', 'new_excerpt_length' );

// Replaces the excerpt "Read More" text by a link
function new_excerpt_more( $more ) {
    global $post;
    return '<a class="more-link" href="'. get_permalink($post->ID) . '">Fortsett å lese</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');

But it doesn't work! The arrow is still there.

I've read in the codex that some of Wordpress themes have their own filter settings on "Read More", and that I need to use remove_filter() to remove them. I tried using the filter from https://codex.wordpress.org/Customizing_the_Read_More

I've searched the function.php for anything that includes the word excerpt, read more or twentyfourteen filter, but didn't find anything.

1
  • Hi Anna, Your code looks OK have you added it to your child themes functions.php file? Also have you activated your child theme or is twenty fourteen still the active theme?
    – Aron
    Commented Oct 9, 2016 at 13:58

1 Answer 1

2

In the twenty fourteen theme there is a plugable function named twentyfourteen_excerpt_more which generates the read more links. This function can be overridden in your child theme to use your custom read more link. All you need to do is add the following to your child theme's functions.php file:

/**
 * Overrides the parent function that generates the read more links
 * 
 * @param string $more
 *
 * @return string
 */
function twentyfourteen_excerpt_more( $more ) {
    global $post;

    return '<a class="more-link" href="'. get_permalink($post->ID) . '">Fortsett å lese</a>';
}
add_filter( 'excerpt_more', 'twentyfourteen_excerpt_more' );

Just for reference the parent function is located in twentyfourteen/inc/template-tags.php and looks like this:

if ( ! function_exists( 'twentyfourteen_excerpt_more' ) && ! is_admin() ) :
/**
 * Replaces "[...]" (appended to automatically generated excerpts) with ...
 * and a Continue reading link.
 *
 * @since Twenty Fourteen 1.3
 *
 * @param string $more Default Read More excerpt link.
 * @return string Filtered Read More excerpt link.
 */
function twentyfourteen_excerpt_more( $more ) {
        $link = sprintf( '<a href="%1$s" class="more-link">%2$s</a>',
                esc_url( get_permalink( get_the_ID() ) ),
                        /* translators: %s: Name of current post */
                        sprintf( __( 'Continue reading %s <span     class="meta-nav">&rarr;</span>', 'twentyfourteen' ), '<span class="screen-reader-text">' . get_the_title( get_the_ID() ) . '</span>' )
                );
        return ' &hellip; ' . $link;
}
add_filter( 'excerpt_more', 'twentyfourteen_excerpt_more' );
endif;
2
  • 2
    It worked like a wonder! Thank you so so much for the help! Can I ask if there is an overview online over where to find the different filters, hooks etc in the different twenty-something themes? Or do I have to manually search?
    – Anna
    Commented Oct 9, 2016 at 19:14
  • 1
    That's great news Anna! I am pleased to hear my answer worked for you, please can you mark my answer as the accepted answer. With regard to finding the hooks and actions there is no documentation I could find, so you will need to search through the code base manually unfortunately.
    – Aron
    Commented Oct 9, 2016 at 23:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.