最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugin development - Styles don't load correctly. Insecure content

programmeradmin4浏览0评论

I'm a newby developing plugins for Wordpress.

When I try to enqueue a style, Wordpress shows the following error: Insecure Content.

The code I use to 'attach' the css files is the following one:

add_action('wp_enqueue_scripts', 'callback_for_setting_up_scripts');

function callback_for_setting_up_scripts(){
  wp_register_style('estilo', __DIR__ . '/assets/css/estilo.css');
  wp_enqueue_style( 'estilo' );
}

This code is located in the /modules folder of the main plugin because it's the style for a specific module.

I use Query Monitor Plugin as a debugger.

Any idea?

Thanks in advance

I'm a newby developing plugins for Wordpress.

When I try to enqueue a style, Wordpress shows the following error: Insecure Content.

The code I use to 'attach' the css files is the following one:

add_action('wp_enqueue_scripts', 'callback_for_setting_up_scripts');

function callback_for_setting_up_scripts(){
  wp_register_style('estilo', __DIR__ . '/assets/css/estilo.css');
  wp_enqueue_style( 'estilo' );
}

This code is located in the /modules folder of the main plugin because it's the style for a specific module.

I use Query Monitor Plugin as a debugger.

Any idea?

Thanks in advance

Share Improve this question asked Apr 23, 2020 at 12:09 VicentGNVicentGN 112 bronze badges 1
  • Welcome to WordPress Development. I hope you find the answer(s) you are looking for. Our site is different from most - if you have not done so yet, consider checking out the tour and help center to find out how things work. – Matthew Brown aka Lord Matt Commented Apr 23, 2020 at 20:37
Add a comment  | 

1 Answer 1

Reset to default 1

__DIR__ returns the current file system path, not a URL. So the resulting stylesheet will not be a valid URL, and will not have https://, causing the insecure content warning.

To get the URL for a stylesheet in your plugin, you need to use plugins_url():

wp_register_style( 'estilo', plugins_url( 'assets/css/estilo.css', __FILE__ ) );

The use of __FILE__ here is described in the documentation for the function:

A full path to a file inside a plugin or mu-plugin. The URL will be relative to its directory. Typically this is done by passing __FILE__ as the argument.

发布评论

评论列表(0)

  1. 暂无评论