Last active
April 10, 2019 05:00
-
-
Save hafizrahman/e18f946b66abd3266cab53dfeade08a4 to your computer and use it in GitHub Desktop.
WordPress: Add body class (for single post template) or post class (for blog/archive pages) "made-with-gutenberg" for posts/pages created with Gutenberg editor.
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
// add class to body class on single post template | |
function themeprefix_body_class_blocks( $classes ) { | |
if ( is_singular() && has_blocks() ) { | |
$classes[] = 'made-with-gutenberg'; | |
} | |
return $classes; | |
} | |
add_filter( 'body_class', 'themeprefix_body_class_blocks' ); | |
// Add class to post classes in blog page or archive pages. | |
function themeprefix_post_class_blocks( $classes ) { | |
if ( is_archive() || is_home() ) { | |
if ( has_blocks() ) { | |
$classes[] = 'made-with-gutenberg'; | |
} | |
} | |
return $classes; | |
} | |
add_filter( 'post_class', 'themeprefix_post_class_blocks' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on the code example in WordPress/gutenberg#4418 (comment)
Try on your own risk :)
Add it using a code snippets plugin.