woocommerce failed to load resource

2019-09-19 15:47发布

add_action( 'admin_menu', array($this, 'admin_menu'), 100 );

public function admin_menu() {
    $page = add_submenu_page( 'edit.php?post_type=product', __( 'ajaxmain' ), __( 'ajaxmainagain' ), apply_filters( 'woocommerce_csv_product_role', 'manage_woocommerce' ), 'ajaxmain-product', array( $this, 'output' ) );
}

public function output() {
    include( 'ajaxmain.php' );
}

i have attached 2 screenshots. it goes and adds ajaxmainagain to the submenu. when i click on it, it loads ajaxmain.php. however it fails to load stylesheets, scripts. the scripts and stylesheets are in the same directory as ajaxmain.php. it is looking for scripts and stylesheets in wp-admin directory. thanks for the help. unable to find resource http://localhost/wordpress/wp-admin/ajax1.php?stateofmachine=xm234jq&q=2. the resource is in plugins directory.

Resource not found

submenu ajaxmainagain

1条回答
姐就是有狂的资本
2楼-- · 2019-09-19 15:53

You need to load your style/script like this.

wp_register_style('custom-style', plugins_url("/path/to/style.css"), '', true );
wp_enqueue_style('custom-style');

wp_register_script('custom-script', plugins_url("/path/to/script.js"), '', true );
wp_enqueue_script('custom-script');

and with this plugin_url you will get the path till your plugin directory like eg. http://localhost/wordpress/wp-content/plugins/sample-plugin/

查看更多
登录 后发表回答