[英]Wordpress Plugin wont load css
My add_action() isn't working and i have no clue why. 我的add_action()无法正常工作,我也不知道为什么。
This is my php 这是我的PHP
function mapstyle() {
wp_register_style('mapstyle', plugins_url('assets/css/mapstyle.css' , __FILE__ ));
wp_enqueue_style('mapstyle');
}
add_action( 'admin_init','mapstyle');
My css is in 'plugin_folder_name/assets/css/mapstyle.css' 我的CSS位于“ plugin_folder_name / assets / css / mapstyle.css”中
Try changing your code to the following. 尝试将代码更改为以下内容。 Also ensure that you do a hard refresh with CTRL + F5 or CTRL + SHIFT + R to clear cache, sometimes changes will not show up unless cache is cleared.
还要确保使用CTRL + F5或CTRL + SHIFT + R进行硬刷新以清除缓存,有时除非清除缓存,否则更改不会显示。
function mapstyle() {
//last parameters set to true loads css in the footer instead of header
wp_enqueue_style('mapstyle', plugins_url('assets/css/mapstyle.css' , __FILE__ ), array(), false, true);
}
add_action( 'wp_enqueue_scripts','mapstyle');
Here is link to documentation of wp_enqueue_style. 这里是链接到wp_enqueue_style的文档。
Edit: My bad, half way through writing answer forgot you wanted to enqueue css and not js :D 编辑:我的糟糕,写答案的一半忘了你想加入css而不是js:D
Depends on where you want to enqueue the styles--admin vs. front-end: 取决于您要排入样式的位置-管理员还是前端:
Admin: 管理员:
add_action('admin_init', 'mapstyle');
Front-end: 前端:
add_action('wp_enqueue_scripts', 'mapstyle');
Reference: https://developer.wordpress.org/reference/functions/wp_enqueue_style/ 参考: https : //developer.wordpress.org/reference/functions/wp_enqueue_style/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.