I'm confused on how to run my custom shortcode in my child theme. To my understanding, I should be only including/requiring the file in the functions.php in my child theme right?
My File Structure is like this
**Child Theme**
-functions.php
-deals
--deals.php
In my functions.php i just place the code
require_once('deals/deals.php' );
And in my deals.php, I have this shortcode
add_shortcode('show-deals','show_deals');
function show_deals() {
return 'Show Deals';
}
So it doesn't get rendered. Help
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 am using Splash theme from StylemixThemes. I am trying to create a child theme in order to edit some things but when I am activating it I do not get the same result as the parent theme.
Inside the child theme folder I have the style.css and the functions.php. Here is the functions.php code
<?php
add_action('wp_enqueue_scripts', 'enqueue_parent_theme_styles'); function enqueue_parent_theme_styles() {
wp_enqueue_style('parent-style', get_template_directory_uri().'/style.css'); }
I am attaching a screenshot for both parent and child theme to show the difference.
parent
child
I am wondering if there is a solution or if there is something I am missing.
Thanks in advance!
You can create your custom child theme learning from wpbeginner.com
I am using Woocommerce Storefront theme and I want to replace the original header with a custom header that I created in elementor. I have a shortcode for the new header but I don't know how to insert it into the code. I am using a blank storefront child theme and there is a function.php file and style.css file.
Thanks for the help.
Just copy the header.php from the parent theme and paste it inside the child theme. Then you can already put your custom code in it.
Reference: codex.wordpress.org/Child_Themes
You can do this in your child theme by using a hook on init
Something like this:
add_action('init', 'replace_header' );
function replace_header(){
remove_action( 'storefront_header', 'storefront_primary_navigation', 50 );
add_action('storefront_header', 'my_custom_header', 50);
}
function my_custom_header(){
do_shortecode('[your_elementor_header_shortcode attr1="value1"]')
}
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