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 :)
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 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.
I'm using a child theme with HTML5 Blank as the parent theme. I've used this before without any issue but for some reason I'm now getting the following error on my themes page -
Broken Themes
The following themes are installed but incomplete.
Name Description
HTML5 Blank Child Theme The parent theme is missing. Please install the "html5blank" parent theme.
This is what I have in my folder -
style.css
/*
Theme Name: HTML5 Blank Child Theme
Description: A child theme of the HTML5 Blank WordPress theme
Author: Mike Whitehead
Template: html5blank
Version: 1.0.0
*/
I've tried numerous different variations on this - also copying the official wordpress guide. The above wording worked for me on my last project so don't know why it won't work now.
This is my functions file -
functions.php
<?php
function my_theme_enqueue_styles() {
$parent_style = 'html5blank-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style ),
wp_get_theme()->get('Version')
);
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
?>
Not sure why this isn't working. Any assistance would be appreciated.
The child themes style.css 'Template' tag should match that of the parent themes folder name eg.
/*
Theme Name: HTML5 Blank Child Theme
Description: A child theme of the HTML5 Blank WordPress theme
Author: Mike Whitehead
Template: html5blank-stable
Version: 1.0.0
*/
As per the WordPress Codex page on Child Themes - https://codex.wordpress.org/Child_Themes
"The Template line corresponds to the directory name of the parent theme. The parent theme in our example is the Twenty Fifteen theme, so the Template will be twentyfifteen. You may be working with a different theme, so adjust accordingly."
Get Your Parent Theme's Textdomain and put it as child theme's Template name. Let's say your Parent theme's Style.css header like this...
/*
Theme Name: HTML5 Parent Theme
Description: A HTML5 Blank Parent WordPress theme
Author: Mike Whitehead
Text domain: html5blank
Version: 1.0.0
*/
Then you can use this Text domain name into your child theme like this..
/*
Theme Name: HTML5 Blank Child Theme
Description: A child theme of the HTML5 Blank WordPress theme
Author: Mike Whitehead
Template: html5blank
Version: 1.0.0
*/
I made a child theme. The CSS I integrated into my child theme and it works perfectly. But now I want to make some amendments in my themes functionality. I copy from my parent theme, for example, product-tab.php to an exact direction in my child theme, modify the file, save, but after refresh no changes in my page. If I do it in the parent theme it works. I think that I should integrate that product-tab.php into my functions.php file (I mean that information first get from my child theme directory not from parent theme by default), but I don't know how because I'm a newbie in PHP coding.
Can anybody give one example how to integrate any PHP file from parent theme to a child theme. Can anybody write an example of a code using the information below?
parent theme direction:
/public_html/wp-content/themes/aloshop/7upframe/element
file name: product-tab.php
child theme direction:
/public_html/wp-content/themes/aloshop-child/7upframe/element
Thank you in advance
If your child theme style sheet is working then you have created the child theme properly. Still reminding you to check the name of parent name included in child theme style.css as 'Template : '
For overwriting the functions you have to copy the php file/functions from parent theme in the same hierarchy or by keeping the same folder file structure.
If your function is still working from parent theme just check from where your function is getting called. It may be from any other file from parent theme which is not included in child theme. In such case, include that file too to he child theme.
Hope this is clear.
If you are using child theme to modify your parent theme {aloshop} then use get_stylesheet_directory() function to get the child theme directory. and then call your other files via functions.php file . To include product-tab.php file via functions.php then put below codes into your child theme's functions.php file,
<?php include_once( get_stylesheet_directory() . '/product-tab.php'); ?>
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