I have added a small custom function to display a little author bio blurb at the bottom of each blog entry in my functions.php file inside the current theme that I am using. So far so good, it is working great but I noticed that this function is being applied to every page, for example it is showing up at the bottom of my “Contact” page.
Here is an example of what I’m talking about to give a visualization of what is happening:

Here is the code I am using for my function:
function get_author_bio ($content=''){
global $post;
$post_author_name=get_the_author_meta("display_name");
$post_author_description=get_the_author_meta("description");
$html.="<div class='author_text'>n";
$html.="<h4>About the Author: <span>".$post_author_name."</span></h4>n";
$html.= $post_author_description."n";
$html.="</div>n";
$html.="<div class='clear'></div>n";
$content .= $html;
return $content;
}
add_filter('the_content', 'get_author_bio');
How can I make this function only be applied to my home page for blog posts and not other pages on my site?
Hopefully that is enough to help me, but I can update this questions to provide any other information that you may need. Thanks.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Check for the type of the page:
function get_author_bio ($content=''){
if ( ! is_single() ) // not a blog post, stop immediately
{
return $content;
}
global $post; // continue with regular work
The easiest way to learn these check functions is a look at the function get_body_class(). Here are the most important:
is_rtl() is_front_page() is_home() is_archive() is_date() is_search() is_paged() is_attachment() is_404() is_single() is_page() is_singular() // same as is_page() and is_single() is_attachment() is_archive() is_post_type_archive() is_author() is_category() is_tag() is_tax() is_user_logged_in() is_admin_bar_showing()
You can even combine them:
// search results, not the first page if ( is_search() and is_paged() ) // attachment and user has probably a profile if ( is_attachment() and is_user_logged_in() )
Some of these functions accept parameters to restrict the result:
// contact page only if ( is_page( 'contact' ) ) // this post was written by the tooth fairy if ( is_author( 'tooth-fairy' ) )
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0