errors - Enqueued stylesheet appends query string, causing "SyntaxError: Invalid or unexpected token"

function renderProductPageUi() {wp_enqueue_style('stylesheetHandle', plugins_url('pluginNamesemanticdis

function renderProductPageUi() {
  wp_enqueue_style('stylesheetHandle', plugins_url('pluginName/semantic/dist/semantic.css'));

  require_once ('templates/offerBox.php');
}
add_action('woocommerce_after_add_to_cart_button', 'renderProductPageUi');

In Chrome browser I see this red console error:

http://localhost/wptest2/wp-content/plugins/pluginName/semantic/dist/semantic.css?ver=5.1.1
SyntaxError: Invalid or unexpected token 

Notice the ?ver=5.1.1 at the end. I vaguely recall this being a wordpress behavior. Is that what is causing the console error? If so how should it be corrected?

function renderProductPageUi() {
  wp_enqueue_style('stylesheetHandle', plugins_url('pluginName/semantic/dist/semantic.css'));

  require_once ('templates/offerBox.php');
}
add_action('woocommerce_after_add_to_cart_button', 'renderProductPageUi');

In Chrome browser I see this red console error:

http://localhost/wptest2/wp-content/plugins/pluginName/semantic/dist/semantic.css?ver=5.1.1
SyntaxError: Invalid or unexpected token 

Notice the ?ver=5.1.1 at the end. I vaguely recall this being a wordpress behavior. Is that what is causing the console error? If so how should it be corrected?

Share Improve this question asked Oct 8, 2019 at 9:26 Sean DSean D 3878 silver badges21 bronze badges 2
  • 1 Is that your actual code? The error message suggests you’ve tried to enqueue a CSS file as JavaScript. – Jacob Peattie Commented Oct 8, 2019 at 9:41
  • That was indeed the problem, I had a duplicate line, except wp_enqueue_script() for the semantic.js file but forgot to change the extension – Sean D Commented Oct 8, 2019 at 10:00
Add a comment  | 

1 Answer 1

Reset to default 2

To elaborate on my comment: SyntaxError: Invalid or unexpected token is not an error that you will ever see related to CSS. This is a JavaScript error that occurs when there's a syntax error in some JavaScript. If you see this error and it's occurring in a CSS file, then it means that you have improperly loaded a CSS file in <script> tag, which means the browser will try to parse the CSS as JavaScript, which will inevitably produce a syntax error, because CSS is not valid JavaScript.

This will happen in WordPress if you try to use wp_enqueue_script() on a CSS file. Make sure you only use wp_enqueue_script() for JavaScript files, and wp_enqueue_style() for CSS files.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745097105a4611045.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信