I'm creating a child theme for an active template. have this code in functions.php file at child folder.
<?php
add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
function enqueue_parent_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
}
?>
but some of js and css files of a plugin named lightgallery haven't loaded when child theme is active. and has 404 error at console. the url of 404 is like this:
wp-
content/themes/sampletheme-child/assets/plugins/LightGallery/assets/css/lightgalle
ry.css
I haven't such a folder in child theme and it is searching it in child theme.I don't know why it doesn't read it from parent theme.
what should I do to load this files?
--ps: another issue is when the child theme is activated the theme is ltr. and the style is not perfect, although the main styles of the themplate has been loaded and I didn't found any rtl style at parent theme. but in parent style every thing is fine and rtl.
Related
I am creating custom WordPress theme. I have a child theme and parent theme.
One issue is my child theme function.php file not adding bootstrap files, So I called it in parent theme, but now the issue I am getting is bootstrap CSS taking priority over my child style.css.
I have tried this code in my child theme function.php file but its not working.
Its not showing any custom.css in view source. I have both files in correct path
add_action('wp_enqueue_scripts', 'theme_enqueue_styles', 100);
function theme_enqueue_styles()
{ $parent_style = 'flambird-style';
$child_style = array('flambird-style');
wp_enqueue_style($parent_style, get_template_directory_uri() . '/bootstrap/custom.css', array());
wp_enqueue_style('child-style', get_stylesheet_directory_uri() . '/css/custom.css', $child_style);
}
its not adding custom in both condition. I think my child theme function.php file is not working.
Please help me on this. I want to use child theme css file.
enter image description here
Add !important to your css formats when there is a conflict, or host your own copy of Bootstrap with compatible changes.
I'm building a wp child theme of ThemeGrill's ColorMag. When I load the page, my child theme css file is loaded, but there is also a file called style.css?ver=5.3.2 loaded after it. When I look at the code under elements in the dev tools, it appears to be a cached version of my style.css file.
I've deleted the child theme folder and reuploaded all of my files but I see the same result. I also have wp-cache level set to 0
Also I should note, I'm new to wp and couldn't figure out how to enqueue the child theme properly, so style.css is loaded via an href in my header.php. my functions.php looks like this:
<?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
Again, I'm new so any best practices you have would be much appreciated!
Site is here.
I have coruscate premium theme and I am making a child theme for it. To modify the php file I copied the file and paste it in the child theme including directory path. But it doesn't work.
I copied framework/widget.php file from parent theme and paste it to child theme folder but it didn't work.
What is the correct method of overriding the parent theme files?
You need a style.css file set up in your child theme that tells wordpress it is the child etc... then you select your child theme within admin and then things will work. See https://codex.wordpress.org/Child_Themes for more information.
For creating a child theme, make a folder inside your 'themes' folder with you child theme name. Now the child theme should have a style sheet in it which is a must. So add a style sheet and the beginning of the child theme style sheet should be as follows:
/*
Theme Name: (theme name) Child
Theme URI: (give URL)
Description: (give description)
Version: (give your version)
Author: (author name)
Author URI: (give URL)
Template: (name of parent theme)
*/
Of these the very important thing is the 'Template' which is the parent theme name. To avoid confusion take the name of parent theme from the parent theme style sheet.
Now the second thing is the functions of your child theme. Just add a php file with the name functions.php and place the below code
<?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
?>
It worked for me :)
Why do you have to enqueue the parent theme stylesheet in a WordPress child theme? I've created style.css in the child theme and when I add a change to it, it works without the functions.php file that enqueues the parent stylesheet, such as changing the background color of an element. I've searched for and answer but can find nothing that tells my why. Everything just says that you have to.
When it comes to loading the styles in WordPress themes there are many ways to skin a cat.
Parent enqueues child style.css -
In some themes the parent style.css is enqueued with wp_enqueue_style() within the parent theme php code.
The 2015 default theme is an example of this method. In functions.php line 233 there is the line wp_enqueue_style( 'twentyfifteen-style', get_stylesheet_uri() );. When the theme is standalone get_stylesheet_uri() returns the theme's own style.css. When a child theme is present get_stylesheet_uri() returns the child theme style.css.
The above is the likely case for your parent theme.
Child enqueues parent style.css -
From the child theme you can load the parent styles by by one of two methods.
enqueue_style() with parameters pointing to the parent theme. Some php similar to: wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );. This is the method you are talking about.
#import from within the child theme style.css file. A typical line of code for this would read: #import url( '../parent-theme-folder/style.css' );. This is not ideal as #import slows down your page load time.
Better Method - Don't use root style.css
It's not strictly necessary to use style.css in the root folder at all. The only thing WordPress strictly needs this file for is to read the theme information in the top comments. This very requirement means that the style.css can't be minimised, or at least is a pain to minimise. Minimising is the process of removing all the spaces in a file of code to reduce the file size. This reduces page load speed.
So now a lot of modern themes are enqueuing their main style from a different minimised css file in a theme subfolder. The main style.css simply consists of the informational comment section read by the core php code but not loaded on the front end.
I'm working on my first child theme and I'm running into a lot of confusion with directories and child themes.
I won't use my real website but I have made a directory in my cPanel dedicated to working on my theme which is at www.wp.example.com
Lets call the template testTemplate. I made a child template called testTemplate-child following the Wordpress codex meaning I registered the parent theme in the child theme's function.php
So wp.example.com loads the style from both the parent theme and the child theme which is desired. What it does not load is the javascript files I enqueued in my child theme's functions.php file.
The confusing part is this, if I navigate to www.wp.example.com/testTemplate-child/ my javascript loads up and works.
I'm wondering if anyone can clear this up for me, why does my child's function.php only work in wp.example.com/testTemplate-child.
It's because your child's theme function.php is added before parent's function.php, that's why you can't override some options, also keep in mind that you'll need to call get_stylesheet_directory() to get child's theme path, because if you do another function, it will load parent's path.
Example to load a javascript file located a /js folder:
$jsPath = get_stylesheet_directory() . '/js/yourScript.js';
wp_enqueue_script( 'child-js', $jsPath, array(), '1.0', true )
More info at: https://codex.wordpress.org/Child_Themes