Can I and How would I add a filter in the function.php that would add a HTML element around the content when the_content is used? This would be similar to what you can do with the_title. i.e:

the_title( '<h1>', '</h1>' );

What I need is to add a section element around the content containing a class similar to:

the_content('<section class="content_wrap">', '</section>');

I know I can:

<section class="content_wrap">
    <?php the_content ?>

But if I can filter it in, it would GREATLY reduce the number of php open and close tags by minimizing a lot of the code in the template files [and also i can mindlessly code more w/o having to remember to add the tags - LOL].

Any help will be greatly appreciated. Thnx!


This is what i needed:

function content_filter($content) {
    return '<section class="content_wrap">' . $content . '</section>';
add_filter( 'the_content', 'content_filter', 6);

1 Answer 1


Here's an example that should work for you:

add_filter('the_content', 'filter_content');

function filter_content($content){

  return $content = "<div class='myclass'>" . $content . "</div>";


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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