2

wordpress如何在没有自定义html的主题添加JS代码

 2 years ago
source link: https://www.huhexian.com/28592.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

wordpress如何在没有自定义html的主题添加JS代码

2022-02-2410:42:12评论317字

今天我另一个商城需要添加全站自定义以及指定页面的JS代码,需要苹果封装,目的在于防止JS跳转,这里就把教程记录下,以免丢失。

wordpress如何在没有自定义html的主题添加JS代码

来到主题目录下的 functions.php 里,将该代码添加即可

  1. function wpb_hook_javascript() {
  2. ?>
  3. // 你的代码
  4. <?php
  5. add_action('wp_head', 'wpb_hook_javascript');

或者添加指定的JS代码

  1. function wpb_hook_javascript() {
  2. if (is_single ('16')) {
  3. ?>
  4. // 你的JS代码
  5. <?php
  6. add_action('wp_head', 'wpb_hook_javascript');

wordpress如何在没有自定义html的主题添加JS代码
测试代码,已经删掉。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK