• Resolved gavleson

    (@gavleson)


    I’d like to modify the “read more”-tag link text behavior in this theme. Maybe I’ve overlooked some setting tucked away somewhere, but Treville doesn’t seem to indicate to the reader that only part of the post is displayed when you insert the more-tag, and I don’t particularly like that. The default behavior seen in “Twenty Seventeen” is much better, IMO. I’ve read up on WP Codex — e.g.

    https://codex.www.ads-software.com/Customizing_the_Read_More

    — and other sites, tried a bunch of stuff to get this theme to display some kind of link, but without any success. I’m at a loss here, how exactly do I get this theme to display the read more link text?

    • This topic was modified 7 years, 4 months ago by gavleson.
    • This topic was modified 7 years, 4 months ago by gavleson.
Viewing 1 replies (of 1 total)
  • Thread Starter gavleson

    (@gavleson)

    I finally figured it out myself…

    1. Create a child theme
    2. In the child theme, edit /template-parts/content.php on line 26 to replace
      <?php the_excerpt(); ?>

      with

      <?php 
      	if( strpos( $post->post_content, '<!--more-->' ) ) { 
      		the_content();
      	} else { 
      		the_excerpt(); 
      	}
      ?>
    3. In the child theme, add the following code to functions.php:
      // override parent theme's 'read more' for excerpts
      function child_theme_setup() {
      	remove_filter( 'excerpt_more', 'treville_excerpt_more' ); 
      }
      add_action( 'after_setup_theme', 'child_theme_setup' );
      
      // use custom 'read more' link on excerpts
      function new_excerpt_more($more) { 
      	global $post;
      	return '<a class="moretag" href="'. get_permalink() . '">[Read more]</a>';
      }
      add_filter('excerpt_more', 'new_excerpt_more');
      
      // add a 'read more' link to hand-crafted excerpts 
      function manual_excerpt_more( $excerpt ) {
      	$excerpt_more = '';
      	if( has_excerpt() || $has_teaser == true) {
      		$excerpt_more = '&nbsp;<a href="' . get_permalink() . '" rel="nofollow">[Read more]</a>';
      	}
      	return $excerpt . $excerpt_more;
      }
      add_filter( 'get_the_excerpt', 'manual_excerpt_more' );
      
      // use custom 'read more' link on posts with <!--more--> tag
      function new_read_more_link() { 
      	return '<a class="more-link" href="' . get_permalink() . '">[Read more]</a>';
      }
      add_filter( 'the_content_more_link', 'new_read_more_link');

    Edit CSS and classes to fit your wish.

Viewing 1 replies (of 1 total)
  • The topic ‘Display more-tag link text’ is closed to new replies.