• Resolved stewardccm

    (@stewardccm)


    I’m trying to develop a new block theme with the full site editor.

    I found that if I wanted to include custom stylesheets, I had to use the add_editor_style function in the admin_init hook.

    However, I can’t find any other way to make the full site editor support custom scripts.

    I was wondering is there any other way to include custom stylesheets and javascript in the full site editor?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Maybe you want to give this a try:

    1.) Add the css rules in the block-editor.css file

    2.) Make sure both the functions.php and block-editor.css file are in the root of your theme or child theme folder.

    3.) Placed the following in your theme or child theme functions.php file:

    add_action( 'enqueue_block_editor_assets', function() {
        wp_enqueue_style( 'your-handle-here', get_stylesheet_directory_uri() . "/block-editor.css", false, '1.0', 'all' );
    } );

    Hello,

    How are you doing with your question?

    If your issue has been resolved, it’s a good practice to mark this topic as “Resolved” per forum guidelines. You can mark the topic with the “Status” drop-down menu located on the right sidebar of this page.

    This can also help out other users.

    Thanks.

    Thread Starter stewardccm

    (@stewardccm)

    Sorry for the late reply, the method you provided only works with CSS styles, not Javascript. Do you have any way to include custom Javascript in the full site editor?

    thanks.

    Perhaps give following a try, adapted to enqueue both css and js:
    (css files now in /css/ folder and use wp_enqueue_style() for css files ; js files now in /js/ folder and use wp_enqueue_script() for js files)
    (also switched to using get_template_directory_uri())

    1.) Add the css rules in theblock-editor.css file. Add js scripts to the block-editor.js file.

    2.) Make sure functions.php file is in the root of your theme or child theme folder. Make sure block-editor.css is in the /css/ folder and block-editor.js is in the /js/ folder of your theme or child theme folder.

    3.) Place the following in your theme or child theme functions.php file:

    
    add_action( 'enqueue_block_editor_assets', function() {
    	wp_enqueue_style( 'your-css-handle-here', get_template_directory_uri() . '/css/block-editor.css', array(), '1.0', 'all' );
    	wp_enqueue_script('your-js-handle-here', get_template_directory_uri() . '/js/block-editor.js', array(), '1.0.0', 'true' );
    } );
    
    Thread Starter stewardccm

    (@stewardccm)

    That’s great. Thank you for your help.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to include custom stylesheet and script in full site editor?’ is closed to new replies.