Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

As a proof of concept, I'd like to create a simple plugin that loads some content, say "hello world" just after the_content on the home page only. How can I do this from a plugin?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You mean a filter and a check for is_home()?

add_filter( 'the_content', 'wpse6034_the_content' );
function wpse6034_the_content( $content )
{
    if ( is_home() ) {
        $content .= '<p>Hello World!</p>';
    }
    return $content;
}
share|improve this answer
    
Thought it would be simple :) Thanks Jan! –  Scott B Dec 28 '10 at 19:44
    
Jan, can you tell me how you might alter your example, if I only want my plugin to filter content when the home page is viewed? This example works, but it runs the filter on every page. –  Scott B Jan 6 '11 at 12:53
    
@Scott: Then you want to run add_filter() only when is_home() is true. Remember that you can't check for is_home() only after the query has run, so probably in the init hook? –  Jan Fabry Jan 6 '11 at 13:39
    
Any idea if I want to do something similar? Simple plug-in that creates new custom home page. Nothing comes from active theme. wordpress.stackexchange.com/questions/110118/… –  Radek Aug 17 '13 at 7:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.