duanjian7343 2019-01-02 20:51
浏览 29

Gutenberg前端块样式不适用

I have a block registered that adds different styles to the editor and front end of a block display.

The editor styles are showing, but I can't get the frontend styles to show.

Here is what I have in my index.php file:

<?php

defined('ABSPATH') || exit;

// add_action engueue_block_editor_assets
add_action( 'enqueue_block_editor_assets', 'block_examples_02_stylesheets_block_enqueue_block_editor_assets');

// plugin-name_block-name_function-name
function block_examples_02_stylesheets_block_enqueue_block_editor_assets() {
    wp_enqueue_script(
        // name of script
        'block-examples_02-stylesheets-block-editor',
        // full url of script location
        plugins_url( 'block.build.js', __FILE__ ),
        // dependencies of script
        array( 'wp-blocks', 'wp-i18n', 'wp-element' ),
        // version number
        filemtime( plugin_dir_path( __FILE__) . 'block.build.js')
    );

    wp_enqueue_style(
        'block-examples_02-stylesheets-block-editor',
        plugins_url( 'editor.css', __FILE__ ),
        array('wp-edit-blocks'),
        filemtime( plugin_dir_path( __FILE__) . 'editor.css')
    );

}

// add_action engueue_block_editor_assets
add_action( 'enqueue_block_assets', 'block_examples_02_stylesheets_block_enqueue_block_assets');

// plugin-name_block-name_function-name
function block_examples_02_stylesheets_block_enqueue_block_assets() {

    wp_enqueue_style(
        'block-examples_02-stylesheets-block',
        plugins_url( 'style.css', __FILE__ ),
        array('wp-blocks'),
        filemtime( plugin_dir_path( __FILE__) . 'style.css')
    );

}
  • 写回答

1条回答 默认 最新

  • douchongbc72264 2019-01-02 21:01
    关注

    Ok, so it appears that removing 'wp-blocks' fixes the issue and the block is now reflecting the styling from the style.css file.

    // add_action engueue_block_editor_assets
    add_action( 'enqueue_block_assets', 'block_examples_02_stylesheets_block_enqueue_block_assets');
    
    // plugin-name_block-name_function-name
    function block_examples_02_stylesheets_block_enqueue_block_assets() {
    
        wp_enqueue_style(
            'block-examples_02-stylesheets-block',
            plugins_url( 'style.css', __FILE__ ),
            array(),
            filemtime( plugin_dir_path( __FILE__) . 'style.css')
        );
    
    }
    
    评论

报告相同问题?