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).
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 | |
/** | |
* Registers a specific editor stylesheet for a specific post id. | |
*/ | |
function actusoins_add_editor_styles_by_post_id() { | |
global $pagenow; | |
// Are we on a post edit page ? | |
if ( isset( $pagenow ) && 'post.php' === $pagenow ) { | |
$post_id = $_GET['post']; | |
// Homepage | |
if ( get_option( 'page_on_front' ) == $post_id && file_exists( get_stylesheet_directory() . '/assets/css/editor-style-home.css' ) ) { | |
add_editor_style( 'assets/css/editor-style-home.css' ); | |
} | |
// Blog homepage | |
if ( get_option( 'page_for_posts' ) == $post_id && file_exists( get_stylesheet_directory() . '/assets/css/editor-style-blog.css' ) ) { | |
add_editor_style( 'assets/css/editor-style-blog.css' ); | |
} | |
} | |
} | |
add_action( 'admin_init', '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