-
-
Save sergixnet/954aa6189280fb4fb4237bc7b18fdaff to your computer and use it in GitHub Desktop.
Adding Custom Class to the_content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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