简体   繁体   中英

style.css is not working of wordpress child theme

I made a child theme of WP-ocean but its style.css is not working, before I made the child theme of twenty nineteen and its working with its all functionality but same functions I have added for WP-ocean but its style sheet is not loading so I am doing inline styling. Below is my Function code.

<?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');

Here is the 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;
}

body{ color: #ff8b00!important; }

This is a style in your css file and not an inline style. Write your style in the HTML tag, then it is an inline style and has the highest priority.

I'm not familiar with Wordpress, but in such a case you can assume that Wordpress first loads your stylesheet file, and then overwrites your own file with the style from "twenty nineteen"

You can follow step:

1, The first create function add 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, In file style.css requirement

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

I tried with a different theme astral theme and added this function in my functions.php and my style.css start working

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' );
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM