我为 WordPress 网站制作了一个新主题。我曾经is_page(array(''))
为我的子网站加载某些样式表。当我尝试上传它时,我function.php
只加载了我添加到所有网站的文件(如style.css
、header.css
等)。这是我的全部function.php
内容,您认为问题出在哪里?
<?php
function load_main_stylesheet() {
wp_register_style('style', get_template_directory_uri() . '/style.css', array(), 12, false, 'all');
wp_enqueue_style('style');
wp_register_style('stylesheet', get_template_directory_uri() . '/assets/css/header.css', array(), 11, false, 'all');
wp_enqueue_style('stylesheet');
}
add_action('wp_enqueue_scripts', 'load_main_stylesheet');
function load_certain_stylesheet() {
wp_register_style('page', get_template_directory_uri() . '/assets/css/page.css', array(), 2, false, 'all');
wp_register_style('product_css', get_template_directory_uri() . '/assets/css/product.css', array(), 8, false, 'all');
wp_register_style('sub-category_css', get_template_directory_uri() . '/assets/css/sub-category.css', array(), 5, false, 'all');
wp_register_style('main-category_css', get_template_directory_uri() . '/assets/css/main-category.css', array(), 9, false, 'all');
wp_register_style('front-page_css', get_template_directory_uri() . '/assets/css/front-page.css', array(), 11, false, 'all');
}
add_action('init', 'load_certain_stylesheet');
function enque_certain_stylesheet() {
if (is_page(array('who-we-are'))) {
wp_enqueue_style('page');
}
if (is_page(array('product'))) {
wp_enqueue_style('product_css');
}
if (is_page(array('sub-category'))) {
wp_enqueue_style('sub-category_css');
}
if (is_page(array('main-category'))) {
wp_enqueue_style('main-category_css');
}
if (is_page(array('home'))) {
wp_enqueue_style('front-page_css');
}
}
add_action('wp_enqueue_scripts', 'enque_certain_stylesheet');
function inclue_font() {
wp_register_style('montserrat', '<link href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">', array(), false, 'all');
wp_enqueue_style('montserrat');
}
add_action('wp_enqueue_scripts', 'inclue_font');
function inclue_jquery() {
wp_deregister_script('jquery');
wp_enqueue_script('jquery', get_template_directory_uri() . '/assets/js/jquery-3.5.1.min.js', '', 1, true);
add_action('wp_enqueue_scripts', 'jquery');
}
add_action('wp_enqueue_scripts', 'inclue_jquery');
function load_js() {
wp_register_script('script', get_template_directory_uri() . '/assets/js/script.js', '', 8, true);
wp_enqueue_script('script');
wp_register_script('header', get_template_directory_uri() . '/assets/js/header.js', '', 1, true);
wp_enqueue_script('header');
}
add_action('wp_enqueue_scripts', 'load_js');
function load_certain_js() {
wp_register_script('product_js', get_template_directory_uri() . '/assets/js/product.js', '', 9, true);
wp_register_script('sub-category_js', get_template_directory_uri() . '/assets/js/sub-category.js', '', 9, true);
wp_register_script('main-category_js', get_template_directory_uri() . '/assets/js/main-category.js', '', 10, true);
wp_register_script('autocomplete_js', get_template_directory_uri() . '/assets/js/autocomplete.js', '', 11, true);
}
add_action('init', 'load_certain_js');
function enque_certain_js() {
if (is_page(array('product'))) {
wp_enqueue_script('product_js');
}
if (is_page(array('sub-category'))) {
wp_enqueue_script('sub-category_js');
}
if (is_page(array('main-category'))) {
wp_enqueue_script('main-category_js');
}
if (is_page(array('home'))) {
wp_enqueue_script('autocomplete_js');
}
}
add_action('wp_enqueue_scripts', 'enque_certain_js');
add_theme_support('menus');
add_theme_support('post-thumbnails');
function load_menus() {
$locations = array(
'header' => __( 'Header Menu', 'theme' ),
'sidenav' => __( 'Sidenav Menu', 'theme' ),
'mobile' => __( 'Mobile Menu', 'theme' ),
'footer' => __( 'Footer Menu', 'theme' )
);
register_nav_menus( $locations );
}
add_action( 'init', 'load_menus' );
function custom_logo_setup() {
$defaults = array(
'height' => 100,
'width' => 400,
'flex-height' => true,
'flex-width' => true,
'header-text' => array( 'site-title', 'site-description' ),
);
add_theme_support( 'custom-logo', $defaults );
}
add_action( 'after_setup_theme', 'custom_logo_setup' );
add_image_size('smallest', 300, 300, true);
add_image_size('largest', 800, 800, true);
?>
页面名称是准确的,我重新检查了它们。