How do I add some HTML before & after the content for all posts?

I would like to add following html before & after a post content:

<ol style = "padding:0;margin:0"> 
    // post content
</ol>

How can I do this for all existing posts automatically?

1 Answer
1

Make use of the the_content filter. This way you can adjust/add/remove certain stuff from the content

add_filter( 'the_content', function ( $content )
{
    // Make sure we only target the main query's content, adjust as needed
    if ( !in_the_loop() )
        return $content;

    // We are targeting the correct content, so lets add what we need to
    $new_content="<ol style = "padding:0;margin:0">";
    $new_content .= $content;
    $new_content .= '</ol>';

    return $content = $new_content;
});

Leave a Comment