Skip to content

Instantly share code, notes, and snippets.

@mathetos
Last active July 17, 2017 09:53
Show Gist options
  • Save mathetos/471fb4ff4e1e7bf447f8 to your computer and use it in GitHub Desktop.
Save mathetos/471fb4ff4e1e7bf447f8 to your computer and use it in GitHub Desktop.
Adding Custom Class to the_content
<?php
//Adding custom class to posts is easy with the post_class filter
add_filter('post_class', 'custom_content_class');
function custom_content_class($classes) {
$classes[] = 'custom_class';
return $classes;
}
//Same with adding custom classes to the body of ALL pages/posts
add_filter('body_class', 'custom_content_class');
function custom_content_class($classes) {
$classes = 'custom_class';
return $classes;
}
// But this is not possible with the_content
// The best that I've come up with so far is adding a wrapper
// div inside of the_contentlike so:
add_filter('the_content', 'custom_content_class');
function custom_content_class($content) {
$mcil_class = '<div class="custom_class">';
$mcil_class .= $content;
$mcil_class .= '</div>';
$filteredcontent = $mcil_class;
return $filteredcontent;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment