Skip to content

Instantly share code, notes, and snippets.

@LinzardMac
Created October 30, 2015 20:40
Show Gist options
  • Save LinzardMac/5b18ace5b2427f72c307 to your computer and use it in GitHub Desktop.
Save LinzardMac/5b18ace5b2427f72c307 to your computer and use it in GitHub Desktop.
is_single() and is_singular() not running the filter on the queried object
/*
* Test case #1
*/
add_filter( 'the_title', 'my_add_custom_content' );
function my_add_custom_content( $title) {
if ( is_singular( 'events' ) ):
$postID = get_the_ID();
$html = '<a href="#" class="goingLink setGoing" id="'.$postID.'" data-value="'. $postID .'">I\'m Going</a><div id="fb-root"></div>';
$title .= $html;
endif;
return $title;
}
/*
* Test Case #2
*/
add_filter( 'the_title', 'my_add_custom_content' );
function my_add_custom_content( $title):
$postID = get_the_ID();
$postType = get_post_type( $postID );
if($postType == 'events' && is_single()){
$html = '<a href="#" class="goingLink setGoing" id="'.$postID.'" data-value="'. $postID .'">I\'m Going</a><div id="fb-root"></div>';
$title .= $html;
endif;
return $title;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment