I would like to add some text or image at the start of each post (in a given post layout).

I have found numerous ways to implement this before the content starts ie atop the content (of course, I could just do this by adding the text above <?php the_content(); ?>).

But I want to insert it really at the start of the content–on the same line, like:

HERE IS SOME CUSTOM TEXT and here starts the content entered for the
post.

Any ideas, Community?

1 Answer
1

You can try the following:

! is_admin() && add_filter( 'the_content', function( $content )
{
    if( in_the_loop() )   // <-- Target the main loop
    {
        $prepend = 'HERE IS SOME CUSTOM TEXT'; // <-- Edit your text here
        $content = $prepend . $content;
    } 
    return $content;
}, 9 ); // <-- Choose some priority < 10

where we choose the priority before the content is taken through wpautop.

Leave a Reply

Your email address will not be published. Required fields are marked *