如何在gutenberg预览中将js添加到自定义acf块

时间:2019-11-08 18:41:13

标签: javascript wordpress-gutenberg gutenberg-blocks acfpro

我已经为gutenberg构建了一个自定义滑块ACF块,并且在前端都能正常运行,但是,我无法将幻灯片功能添加到块编辑器预览中。我要去哪里错了?

functions.php中的前端脚本和样式

function pb_theme_scripts() {
    wp_enqueue_script( 'pb_theme-scripts', get_template_directory_uri() . '/js/custom.js', array(), 'jquery', true );
    wp_enqueue_script( 'slick-js', get_template_directory_uri() . '/js/slider.js', array('jquery'), '1.5.3', true );
}
add_action( 'wp_enqueue_scripts', 'pb_theme_scripts' );

我的编辑器样式和我的functions.php中注册的acf块:

add_theme_support( 'align-wide' );
add_theme_support( 'responsive-embeds' );
add_theme_support( 'editor-styles' );
add_editor_style( get_template_directory_uri() . '/css/style-editor.css' );
add_editor_style( get_template_directory_uri() . '/css/slider.css' );

function register_acf_block_types($settings) {
    // featured slider
    acf_register_block_type(array(
        'name'              => 'featured-slider',
        'title'             => __('Feature Slider'),
        'description'       => __('Add posts, pages and/or products to a featured slider.'),
        'render_template'   => 'template-parts/blocks/featured-slider.php',
        'enqueue_script'    => get_template_directory_uri() . '/js/slider.js',
        'category'          => 'widgets',
        'icon'              => 'star-filled',
        'keywords'          => array( 'feature', 'slider' ),
    ));
}

if( function_exists('acf_register_block_type') ) {
    add_action('acf/init', 'register_acf_block_types');
}

0 个答案:

没有答案