ThemeShaper Forums » Thematic

[closed]

Read more link in manual excerpt

(3 posts)
  • Started 4 years ago by gaillen
  • Latest reply from gaillen
  • This topic is resolved
  1. gaillen
    Member

    Is it possible to auto generate a read more link for manual excerpts?

    I can find lots of information to modify the read more link for auto generated excerpts but actually creating one for manually generated seems to not exist?

    Posted 4 years ago #
  2. Hi gaillen-

    I think that the more link behavior of WordPress is more closely tied to building themes with templates than the newer child theme method using filters and actions provided by a theme framework. I still find the excerpt & more-tag variations baffling at times.

    Try this:

    function all_excerpts_get_more_link($post_excerpt) {
    
    	return $post_excerpt . '<a href="'. get_permalink($post->ID) . '">' . 'Read More...' . '</a>';
    }
    add_filter('wp_trim_excerpt', 'all_excerpts_get_more_link');

    You may want to do something with the excerpt_more filter to remove or replace the [...].

    Here are a list of codex pages that may shed some light:

    http://codex.wordpress.org/Customizing_the_Read_More
    http://codex.wordpress.org/Function_Reference/wp_trim_excerpt
    http://codex.wordpress.org/Plugin_API/Filter_Reference/excerpt_more

    -Gene

    Posted 4 years ago #
  3. gaillen
    Member

    Thank you again Gene. That worked and so did the reference to the excerpt more filter. I now have both types of excerpts behaving the same on my posts, categories and archives pages. Much easier to explain to my end user if these all have a consistent behaviour. Now they can choose to manually write the excerpt or let it auto generate with the final product behaving the same for readers in both cases.

    If anyone else is looking for this solution here is the combination in use in my child theme functions.php . Note the addition of a class to the read more permalink to apply CSS styling.

    // Displays excerpt of posts on posts/home page moved to "articles" with static front page
    function childtheme_content($content) {
    	if ( is_home () ) {
    		$content= 'excerpt';}
    	return $content;
    }
    add_filter('thematic_content', 'childtheme_content');
    
    // Custom excerpt length (change the numerical value)
    function new_excerpt_length($length) {
    return 100;
    }
    add_filter('excerpt_length', 'new_excerpt_length');
    
    // Changes the behaviour of manual excerpts to include read more link (note css class)
    function all_excerpts_get_more_link($post_excerpt) {
    
    	return $post_excerpt . '<a href="'. get_permalink($post->ID) . '" class="read-more">' . ' ...continue reading article...' . '</a>';
    }
    add_filter('wp_trim_excerpt', 'all_excerpts_get_more_link');
    
    // Filters [...] from the manual excerpts string
    function new_excerpt_more($more) {
    	return '';
    }
    add_filter('excerpt_more', 'new_excerpt_more');

    -Gaillen

    Posted 4 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.