Skip to content

Instantly share code, notes, and snippets.

@hafizrahman
Last active April 10, 2019 05:00
Show Gist options
  • Save hafizrahman/e18f946b66abd3266cab53dfeade08a4 to your computer and use it in GitHub Desktop.
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.
// 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
Copy link
Author

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