【问题标题】:Is there a plugin to exclude some JavaScripts from specific page / post是否有插件可以从特定页面/帖子中排除一些 JavaScript
【发布时间】:2012-08-23 12:51:17
【问题描述】:

heptasarim.com 中,每个页面和帖子都加载了几个 JavaScript 文件和插件。自然,这种情况会影响页面和帖子的加载速度。我想从特定帖子或页面的标题中排除一些无用的 js 和 css 文件。

有没有可以正常工作的插件还是我必须编写一些代码?

【问题讨论】:

  • 您可以使用诸如 Labjs 或 requirejs 之类的脚本加载器,并在 functions.php 中编写一些简单的魔法
  • 谢谢elclanrs,真的没有修改js和css的插件吗?很有趣。

标签: javascript wordpress


【解决方案1】:

您不需要插件,只需将它们包装在 php 条件语句中即可。

http://codex.wordpress.org/Conditional_Tags

这样做您可以将文件和脚本设置为仅出现在某些页面、帖子、类别、标签等上

【讨论】:

  • 完美。感谢 CoreyRS。实际上我知道那页和声明,但我想确定一下。我开始编码:)
  • 我有一个名为 scripts_init.php 的页面。 Js 文件在该文件中排队。关于插入 js 文件有这么多行。函数themeton_clean_theme_scripts_print() { wp_enqueue_script('jquery'); wp_enqueue_script('jquery-twitter'); wp_enqueue_script('jquery-prettyphoto'); wp_enqueue_script('theme-jquery-ui-custom'); wp_enqueue_script('jquery-validator');
  • 现在我该如何编辑这些行。我认为这种插入是不正确的: wp_enqueue_script('jquery-twitter'); if(is_front_page()) { /jquery.tweet.js };
  • 我明白了。 if(is_front_page()) { wp_enqueue_script('jquery-twitter');}
猜你喜欢
  • 1970-01-01
  • 2023-02-06
  • 1970-01-01
  • 2014-01-14
  • 1970-01-01
  • 1970-01-01
  • 2011-10-10
  • 1970-01-01
  • 2015-10-11
相关资源
最近更新 更多