首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >脚本和样式不在functions.php中排队

脚本和样式不在functions.php中排队
EN

Stack Overflow用户
提问于 2021-03-31 05:50:52
回答 2查看 459关注 0票数 3

我正在转换wordpress主题中的html模板,我试图对functions.php中的样式和脚本进行排队,但有些正在工作,有些没有工作--我的自定义css也不能工作--只有引导类在下面是我的header.php代码:

代码语言:javascript
复制
<?php
 /**
 * Header file for the Twenty Twenty WordPress default theme.
 *
 * @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
 *
 * @package WordPress
 * @subpackage Twenty_Twenty
 * @since Twenty Twenty 1.0
 */

?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* 
these tags -->s
<title> Unistore Pro &middot; Premium Responsive E-Commerce Template</title>

<meta name="description" content="Bootstrap template for you store - E-Commerce Bootstrap Template">
<meta name="keywords" content="unistore, e-commerce bootstrap template, premium e-commerce bootstrap 
template, premium bootstrap template, bootstrap template, e-commerce, bootstrap template, sunrise 
digital">
<meta name="author" content="Sunrise Digital">
<link rel="shortcut icon" type="image/x-icon" href="favicon.png">

<!-- Bootstrap -->
<link href="assets/css/bootstrap.css" rel="stylesheet">
<link href="assets/css/custom.css" rel="stylesheet">
<link href="assets/css/carousel.css" rel="stylesheet">
<link href="assets/ionicons-2.0.1/css/ionicons.css" rel="stylesheet">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<link href='https://fonts.googleapis.com/css?family=Catamaran:400,100,300' rel='stylesheet' 
type='text/css'>

<link href="assets/css/custom-scroll/jquery.mCustomScrollbar.css" rel="stylesheet">

    <?php wp_head(); ?>

</head>

现在是functions.php队列代码的代码:

代码语言:javascript
复制
    function Twenty_twenty_files() { 
    wp_enqueue_style('twentytwenty_style', get_stylesheet_uri()); 
    } 

    add_action('wp_enqueue_scripts', 'Twenty_twenty_files');


    function Twenty_twenty_scripts() { 
    wp_enqueue_script('twentytwenty_script', get_theme_file_uri(), array(), '1.0'); 

    wp_enqueue_script( 'twentytwenty-priority-menu', get_theme_file_uri( '/js/custom- 
   scroll/jquery.mCustomScrollbar.concat.min.js' ), array(), '20181214', true );
        wp_enqueue_script( 'twentytwenty-touch-navigation', get_theme_file_uri( '/js/bootstrap.js' ), 
    array(), '20181231', true );
        wp_enqueue_script( 'twentytwenty-priority-menu', get_theme_file_uri( '/js/bootstrap.min.js' ), 
    array(), '20181214', true );
        wp_enqueue_script( 'twentytwenty-priority-menu', get_theme_file_uri( '/js/carousel.js' ), 
    array(), '20181214', true );
        wp_enqueue_script( 'twentytwenty-priority-menu', get_theme_file_uri( '/js/carousel-product.js' ), 
    array(), '20181214', true );
        wp_enqueue_script( 'twentytwenty-priority-menu', get_theme_file_uri( '/js/checkout.js' ), 
    array(), '20181214', true );
        wp_enqueue_script( 'twentytwenty-priority-menu', get_theme_file_uri( '/js/color-calculations.js' 
    ), array(), '20181214', true );
        wp_enqueue_script( 'twentytwenty-priority-menu', get_theme_file_uri( '/js/core.js' ), array(), 
    '20181214', true );
        wp_enqueue_script( 'twentytwenty-priority-menu', get_theme_file_uri( '/js/customize.js' ), 
    array(), '20181214', true );
        wp_enqueue_script( 'twentytwenty-priority-menu', get_theme_file_uri( '/js/customize-controls.js' 
    ), array(), '20181214', true );
        wp_enqueue_script( 'twentytwenty-priority-menu', get_theme_file_uri( '/js/customize-preview.js' 
    ), array(), '20181214', true );
        wp_enqueue_script( 'twentytwenty-priority-menu', get_theme_file_uri( '/js/editor-script-block.js' 
    ), array(), '20181214', true );
        wp_enqueue_script( 'twentytwenty-priority-menu', get_theme_file_uri( '/js/index.js' ), array(), 
     '20181214', true );
        wp_enqueue_script( 'twentytwenty-priority-menu', get_theme_file_uri( 
    '/js/jquery.touchSwipe.min.js' ), array(), '20181214', true );
        wp_enqueue_script( 'twentytwenty-priority-menu', get_theme_file_uri( '/js/jquery.ui.touch- 
   punch.js' ), array(), '20181214', true );
        wp_enqueue_script( 'twentytwenty-priority-menu', get_theme_file_uri( '/js/jquery-latest.min.js' 
    ), array(), '20181214', true );
        wp_enqueue_script( 'twentytwenty-priority-menu', get_theme_file_uri( '/js/jquery-ui-1.11.4.js' ), 
    array(), '20181214', true );
        wp_enqueue_script( 'twentytwenty-priority-menu', get_theme_file_uri( '/js/masonry.pkgd.min.js' ), 
    array(), '20181214', true );
        wp_enqueue_script( 'twentytwenty-priority-menu', get_theme_file_uri( '/js/npm.js' ), array(), 
    '20181214', true );
        wp_enqueue_script( 'twentytwenty-priority-menu', get_theme_file_uri( '/js/skip-link-focus-fix.js' 
    ), array(), '20181214', true );
        wp_enqueue_script( 'twentytwenty-priority-menu', get_theme_file_uri( '/js/store.js' ), array(), 
    '20181214', true );
    }
    add_action( 'wp_enqueue_scripts', 'Twenty_twenty_scripts' );
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-03-31 06:28:16

确保您为所有wp_enqueue_scriptwp_enqueue_style提供了唯一的句柄。第一个参数是句柄。您还可以使用wp_dequeue_script根据句柄删除js。试试下面的代码。

代码语言:javascript
复制
function Twenty_twenty_scripts() { 
    wp_enqueue_script( 'twentytwenty_script',        get_theme_file_uri(), array(), '1.0'); 
    wp_enqueue_script( 'twentytwenty-priority-menu', get_theme_file_uri( '/js/custom- scroll/jquery.mCustomScrollbar.concat.min.js' ), array(), '20181214', true );
    wp_enqueue_script( 'bootstrap',                  get_theme_file_uri( '/js/bootstrap.js' ), array(), '20181231', true );
    wp_enqueue_script( 'bootstrap-min',              get_theme_file_uri( '/js/bootstrap.min.js' ),  array(), '20181214', true );
    wp_enqueue_script( 'carousel',                   get_theme_file_uri( '/js/carousel.js' ),  array(), '20181214', true );
    wp_enqueue_script( 'carousel-product',           get_theme_file_uri( '/js/carousel-product.js' ),  array(), '20181214', true );
    wp_enqueue_script( 'checkout',                   get_theme_file_uri( '/js/checkout.js' ),  array(), '20181214', true );
    wp_enqueue_script( 'color-calculations',         get_theme_file_uri( '/js/color-calculations.js'  ), array(), '20181214', true );
    wp_enqueue_script( 'core',                       get_theme_file_uri( '/js/core.js' ), array(),  '20181214', true );
    wp_enqueue_script( 'customize',                  get_theme_file_uri( '/js/customize.js' ),  array(), '20181214', true );
    wp_enqueue_script( 'customize-controls',         get_theme_file_uri( '/js/customize-controls.js' ), array(), '20181214', true );
    wp_enqueue_script( 'customize-preview',          get_theme_file_uri( '/js/customize-preview.js' ), array(), '20181214', true );
    wp_enqueue_script( 'editor-script-block',        get_theme_file_uri( '/js/editor-script-block.js' ), array(), '20181214', true );
    wp_enqueue_script( 'index',                      get_theme_file_uri( '/js/index.js' ), array(), '20181214', true );
    wp_enqueue_script( 'touchSwipe',                 get_theme_file_uri( '/js/jquery.touchSwipe.min.js' ), array(), '20181214', true );
    wp_enqueue_script( 'touch- punch',               get_theme_file_uri( '/js/jquery.ui.touch-punch.js' ), array(), '20181214', true );
    wp_enqueue_script( 'jquery-latest',              get_theme_file_uri( '/js/jquery-latest.min.js' ), array(), '20181214', true );
    wp_enqueue_script( 'jquery-ui',                  get_theme_file_uri( '/js/jquery-ui-1.11.4.js' ), array(), '20181214', true );
    wp_enqueue_script( 'masonry',                    get_theme_file_uri( '/js/masonry.pkgd.min.js' ), array(), '20181214', true );
    wp_enqueue_script( 'npm',                        get_theme_file_uri( '/js/npm.js' ), array(), '20181214', true );
    wp_enqueue_script( 'skip-link-focus-fix',        get_theme_file_uri( '/js/skip-link-focus-fix.js' ), array(), '20181214', true );
    wp_enqueue_script( 'store',                      get_theme_file_uri( '/js/store.js' ), array(), '20181214', true );
}
add_action( 'wp_enqueue_scripts', 'Twenty_twenty_scripts' );
票数 1
EN

Stack Overflow用户

发布于 2021-03-31 06:19:10

您可以添加样式和脚本,如下面的代码,您需要添加唯一的所有样式和脚本的id请检查附加的图像,您可以更改id。

wp_enqueue_style('slick',get_stylesheet_directory_uri()。'/assets/css/slick.css';wp_enqueue_script('general',get_stylesheet_directory_uri()。'/assets/js/general.js';

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66882353

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档