Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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.
// 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' );
@hafizrahman

This comment has been minimized.

Copy link
Owner Author

@hafizrahman hafizrahman commented Apr 10, 2019

Based on the code example in WordPress/gutenberg#4418 (comment)

Try on your own risk :)

Add it using a code snippets plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment