Loading a plugin’s js file from functions.php

Question

I’m trying to change the way a plugin register’s its own js file from this:

function gpvd_enqueue_styles_admin() {
    wp_enqueue_style(
        'gpvb-admin-styles',
        plugin_dir_url( __FILE__ ) . 'css/admin.css',
        array(),
        '',
        'all'
    );
    wp_register_script(
        'gpvb-admin-scripts',
        plugins_url( 'js/block.js', __FILE__ ),
        array( 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-editor' ),
        filemtime( plugin_dir_path( __FILE__ ) . 'js/block.js' ),
        false
    );
    wp_enqueue_script( 'gpvb-admin-scripts' );
}

and change the false to a true.

So I put this in my functions.php file:

function sh_child_enqueue_styles_admin() {
    wp_enqueue_style(
        'gpvb-admin-styles',
        plugin_dir_url( __FILE__ ) . 'css/admin.css',
        array(),
        '',
        'all'
    );
    wp_register_script(
        'gpvb-admin-scripts',
        plugins_url( 'js/block.js', __FILE__ ),
        array( 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-editor' ),
        filemtime( plugin_dir_path( __FILE__ ) . 'js/block.js' ),
        true
    );
    wp_enqueue_script( 'gpvb-admin-scripts' );
}

remove_action('admin_enqueue_scripts', 'gpvb_enqueue_styles_admin');
add_action('admin_enqueue_scripts', 'sh_child_enqueue_styles_admin');

However, it can’t find the plugin’s js file because of __FILE__. Do I have to hard code the path in there or is there a better way of accomplishing this?

0
, StevieD 2 years 2020-01-09T08:40:05-05:00 0 Answers 73 views 0

Leave an answer

Browse
Browse