0

How can I modify the_content if the page is the home/start page?

I thought this could be done through a function in functions.php, but soon realized after some googling that the functions.php -file runs before parse query, so WP doesn't now if it is the home/start page or not.

What I want to do: If the post have one or multiple images in it, grab the first image and display it in the loop before the content of the post on the home/start page. I don't want to go with "Featured image".

How do I accomplish this?

0

You can check for is_home() and is_front_page() inside of your filter:

add_filter( 'the_content', function( $content ) 
{
    if ( ! is_home() and ! is_front_page() )
        return $content;

    return 'Home, sweet home!<br>' . $content;
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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