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')
        );
    
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?