WP. Functions integration into child theme - php

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

Related

How to manually create a text-domain for a WordPress child theme?

I don't know how to manually add a text-domain to my child theme.
I installed LocoTranslate to find out what the text-domain was, and it shows the same as the main theme.
This is a problem, but I need to add a file that has been made custom and it must call this child theme in various parts of the code, now it calls the main theme and this is the problem.
Searching I found [WordPress documentation on child themes,][1] but I must say that I don't know how to interpret it, my experience is not enough to know how to read this documentation.
I don't even keep looking and I can't find a site that describes how to do this by someone inexperienced.
Is there a document outlining the steps to create a child theme text-domain for beginners?
Go into the style.css file in your child theme. In the comment header, add a text domain field under the theme name field.
/*
Theme Name: My Child Theme
Text Domain: mychildtheme
*/
Then, go to your functions.php file in your child theme and add the following code.
function mychildtheme_load_textdomain() {
load_child_theme_textdomain( 'mychildtheme', get_stylesheet_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'mychildtheme_load_textdomain' );
Change 'mychildtheme' to the text domain you gave in your style.css file.

Wordpress child theme breaks site appearance

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

Wordpress PHP code for printing child theme directory

I am attempting to use this code <?php echo get_template_directory_uri(); ?> to print out the directory reference to my child theme in Wordpress. It goes to the parent theme instead. Reading the codex here https://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri it appears as though it should retrieve the directory for the child theme if one has been designated.
Am I doing something wrong?
You'll need to use get_stylesheet_directory();. This will go to the current theme, child or parent.
get_template_directory(); will still go to the parent theme if you are using a child theme.

Parent Theme Style Loading After Bootstrap Style

I have created a child theme to my parent theme and am running into an issue. I am using the child theme functions.php file to call the parent theme .css. The issue with this is that the parent style.css is being called before the bootstrap.css only on my child theme. I have tried using the $dependencies argument but it still isn't working. Was looking for an easy correct solution.
wp_enqueue_style('bootstrap-style', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css');
wp_enqueue_style('alphamedia-style', get_stylesheet_uri(), 'bootstrap-style');
That is the code I am using in my parent functions.php file but it still isn't working.
I'm sure it is something simple I am overlooking. Thank you for the help.
Your on the right track with this but the wp_enqueue_style(); function expects an array to be passed as the $dependencies. Try this:
wp_enqueue_style('alphamedia-style', get_stylesheet_uri(), array('bootstrap-style'));

Wordpress Child Theme Path

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

Categories