style.css不适用于wordpress子主题



我制作了一个WP海洋的子主题,但它的样式.css不起作用,在我制作二十世纪十九年代的子主题之前,它使用了我为WP海洋添加的所有功能,但没有加载它的样式表,所以我在做内联样式。下面是我的功能代码。

<?php
add_theme_support('menus');
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
wp_enqueue_style( 'child-style', get_stylesheet_uri() );
}

function wpb_custom_new_menu() {
register_nav_menu('my-custom-menu',__( 'My Custom Menu' ));
}
add_action( 'init', 'wpb_custom_new_menu' );

function my_scripts() {
wp_enqueue_style('bootstrap4', 
'https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css');
wp_enqueue_script( 'boot1','https://code.jquery.com/jquery-3.3.1.slim.min.js', array( 'jquery' 
),'',true );
wp_enqueue_script( 
'boot2','https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js', array( 'jquery' 
),'',true );
wp_enqueue_script( 'boot3','https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js', 
array( 'jquery' ),'',true );
}
add_action( 'wp_enqueue_scripts', 'my_scripts' );

function arphabet_widgets_init() {
register_sidebar(array(
'name' => 'My_Widgtet_Area',
'id' => 'partner-slide',
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2 class="rounded">',
'after_title' => '</h2>',
));
}
add_action('widgets_init', 'arphabet_widgets_init');
function prefix_add_content ($content){
return $content;
}
add_filter ('the_content', 'prefix_add_content');

这是style.css

/*
Theme Name: Oceanwp Child
Theme URI: http://example.com/oceanwp-child/
Description: Oceanwp Child Theme
Author: John Doe
Author URI: http://example.com
Template: oceanwp
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: light, dark, two-columns, right-sidebar, responsive-layout, 
accessibility-ready
Text Domain: Oceanwp-Child
*/
@import
body{
color: #ff8b00!important;
}

您可以执行步骤:

1、第一个创建函数添加style.css

add_action('wp_enqueue_scripts', 'my_theme_enqueue_styles');
function my_theme_enqueue_styles() {
wp_enqueue_style('child-style', get_theme_file_uri('/style.css'));
}

2、文件中样式.css要求

/*
Theme Name:     Theme Child Name
Template:       Parent theme
*/

正文{颜色:#ff8b00!重要的}

这是css文件中的样式,而不是内联样式。在HTML标记中写入您的样式,则它是内联样式,具有最高优先级。

我不熟悉Wordpress,但在这种情况下,你可以假设Wordpress首先加载你的样式表文件,然后用";二十十九";

我尝试了一个不同的主题星体主题,并在我的functions.php和style.css中添加了这个功能,开始工作

add_action( 'wp_enqueue_scripts', 'my_plugin_add_stylesheet' );
function my_plugin_add_stylesheet() {
wp_enqueue_style( 'my-style', get_stylesheet_directory_uri() . '/style.css', false, 
'1.0', 'all' );
}

最新更新