ERROR: Trailing slash when enqueuing styles vs. scripts
-
This works correctly:
<?php $plugin_path = "wp-content/plugins/my_plugin"; wp_enqueue_style("my_style", $plugin_path."/CSS/style.css", false, "1.0", "all"); wp_enqueue_script("my_js", "/".$plugin_path."/JS/scripts.js", false, "1.0"); ?>Notice I had to add a slash when calling “enqueue_script”
Both functions have identical descriptions of $src in the documentation:
“Full URL of the stylesheet, or path of the stylesheet/script relative to the WordPress root directory.”Before adding the slash, the scripts failed. When I examined the source code of my site and saw this:
<script src='https://mysite.comwp-content/plugins/my_plugin/JS/scripts.js?ver=1.0' id='myplugin-js'></script>I think this is a bug, or there needs to be a correction in the documentation.
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
The topic ‘ERROR: Trailing slash when enqueuing styles vs. scripts’ is closed to new replies.