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.
Check for the type of the page:
The easiest way to learn these check functions is a look at the function
get_body_class()
. Here are the most important:You can even combine them:
Some of these functions accept parameters to restrict the result: