Skip to content

Instantly share code, notes, and snippets.

@neilgee
Last active May 19, 2017 00:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save neilgee/49c3b77d42b670b04cc2 to your computer and use it in GitHub Desktop.
Save neilgee/49c3b77d42b670b04cc2 to your computer and use it in GitHub Desktop.
Genesis Conditional Read More and Force Read More
<?php
//Two functions below to set the read more text conditionally - the 2nd function forces the read more as sometimes it does not appear.
//Read More Text For Excerpt - Set conditionally based on Category slug
add_filter( 'excerpt_more', 'genesischild_read_more_link' );
function genesischild_read_more_link( $more ) {
if( in_category('video') ) {//add in category
return '... <a href="' . get_permalink() . '" class="more-link" title="View More">View More</a>';//change read more text
}
else {//what all the other categories get
return '... <a href="' . get_permalink() . '" class="more-link" title="Read More">Read More</a>';
}
}
//Force the Read More - Set conditionally based on Category slug
add_filter( 'the_excerpt', 'themeprefix_excerpt_read_more_link' );
function themeprefix_excerpt_read_more_link( $output ) {
global $post;
if( in_category('video') ) {//add in category
return $output . ' <a href="' . get_permalink( $post->ID ) . '" class="more-link" title="View More">View More</a>';//change read more text
}
else {//what all the other categories get
return $output . ' <a href="' . get_permalink( $post->ID ) . '" class="more-link" title="Read More">Read More</a>';
}
}
@Konq
Copy link

Konq commented Nov 8, 2016

Hi Neilgee,
To start with, let me first tell you that, I am totally new to websites and everything else, I don't ever know how and where to insert codes. Now my problem is that, I am creating my website with the help of a tutorial, and I am using the Sydney theme, before I decided to install the Sydney child plugin, I saw the read more tag was working, but not anymore after this child theme. I would love to have it back for text and videos also. Could you please help me. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment