Im trying to do an if/else on a custom excerpt filter in functions.php file but not having any luck. Heres what I have. What I am trying to do is customize one of the excerpts being generated. I need to have 'Watch Video' instead of the read more for one post. I tried wrapping that in an if (is_single('my page')) but it doesn't have any affect. Any help anyone could provide would be greatly appreciated!


function custom_excerpt($text) { 

  $excerpt = '' . strip_tags($text) . '<span class="readmore"><a href="'.get_the_permalink().'" rel="nofollow">Read More &raquo;</a></span>';

   return $excerpt;
add_filter('the_excerpt', 'custom_excerpt');
  • 1
    is_single( 'my page' ) will return true if my page is a single post, even if you're not on 'my page', in the same way that is_building('house') will always return true, even if you're currently on a lake, you want to check that the current post is 'my page', not that 'my page' is a page
    – Tom J Nowell
    Oct 28, 2016 at 22:18
  • 1
    Also, you shouldn't be including the read more link in your excerpt, there's a different filter and system that takes care of that in the the_content_more_link filter, look at the documentation on the dev handbook for the_excerpt for an example
    – Tom J Nowell
    Oct 28, 2016 at 22:20
  • Thanks Tom. I'm using the the_excerpt() method not the_content() method. Which in the handbook has the link in there albeit I should of used what was in the HB. I must of got that piece of code off a website somewhere. I changed to what the HB has. So thanks for the advice! I'll give a shot. thanks!
    – lnickel
    Oct 29, 2016 at 1:14

1 Answer 1


Here is the solution that seemed to work. Thanks Tom

function new_excerpt_more($more) {
    global $post;
    $thePostID = $post->ID;
    if($thePostID == 1128) {
    return '...<a class="readmore" href="'. get_permalink($post->ID) .  '">Watch Video &raquo;</a>';
    } else {
    return '...<a class="readmore" href="'. get_permalink($post->ID) . '">Read more &raquo;</a>';
add_filter('excerpt_more', 'new_excerpt_more');

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.