Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This is how to assign a specific stylesheet to a specific post type post id on WordPress Gutenberg edit screen. See https://sebastien-meric.com/appliquer-gutenberg-feuille-de-style-post-id/ (in french).
<?php
/**
* Registers a specific editor stylesheet for a specific post id.
*/
function my_theme_add_editor_styles_by_post_id() {
global $post, $pagenow;
// Homepage
if ( isset( $pagenow )
&& 'post.php' === $pagenow
&& get_option( 'page_on_front' ) == $post->ID
&& file_exists( get_stylesheet_directory() . '/editor-style-home.css' )
) {
add_editor_style( get_stylesheet_directory_uri() . '/editor-style-home.css' );
}
// Blog homepage
if ( isset( $pagenow )
&& 'post.php' === $pagenow
&& get_option( 'page_for_posts' ) == $post->ID
&& file_exists( get_stylesheet_directory() . '/editor-style-blog.css' )
) {
add_editor_style( get_stylesheet_directory_uri() . '/editor-style-blog.css' );
}
}
add_action( 'pre_get_posts', 'my_theme_add_editor_styles_by_post_id' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.