For some reason my child theme templates are not being recognized.
I believe I have followed the correct procedure (and checked for caching etc)
/wp-content/themes/divi-child/includes/builder/module/Blog.php
should replace
/wp-content/themes/Divi/includes/builder/module/Blog.php
(same path and same file with a slight update)
The child theme module template is not recognized (changes to the child theme template have no effect)
I have tested editing the main file and this works immediately every
time.
Any advice greatly appreciated.
Cheers
EDIT
The below should work according to Divi however it breaks the site when I try.
Apparently it is not enough to just copy the module into the child theme. The file needs to be duplicated. Then copied file to child-theme/custom-modules/Blog.php. After adding following code to the bottom of the functions.php file:
function divi_custom_blog_module() {
get_template_part( '/custom-modules/Blog' );
$myblog = new custom_ET_Builder_Module_Blog();
remove_shortcode( 'et_pb_blog' );
add_shortcode( 'et_pb_blog', array( $myblog, '_render' ) );
}
add_action( 'et_builder_ready', 'divi_custom_blog_module' );
There are a few other steps https://intercom.help/elegantthemes/en/articles/4532734-moving-blog-module-in-child-theme
Create a new folder in the child theme folder, for example, includes folder.
Now copy the Divi/includes/builder/module/Blog.php file from the parent theme into the child-theme/includes/ folder.
Open up the Blog.php file of your child theme and replace this line (at the very top):
require_once 'helpers/Overlay.php';
class ET_Builder_Module_Blog extends ET_Builder_Module_Type_PostBased {
with:
get_template_part( '/includes/builder/module/helpers/Overlay.php' );
class custom_ET_Builder_Module_Blog extends ET_Builder_Module_Type_PostBased {
Replace: $this->vb_support = 'on'; with $this->vb_support = 'off';
Remove this line from the bottom: new ET_Builder_Module_Blog();
Finally, add the following code to the functions.php file in your child theme folder:
/*================================================
#Load custom Blog Module
================================================*/
function divi_custom_blog_module() {
get_template_part( '/includes/Blog' );
$myblog = new custom_ET_Builder_Module_Blog();
remove_shortcode( 'et_pb_blog' );
add_shortcode( 'et_pb_blog', array( $myblog, '_render' ) );
}
add_action( 'et_builder_ready', 'divi_custom_blog_module' );
I have got this issue similar to this before. I think - maybe the blog template is called by another file in the "father theme" folder some thing like:
$url = dirname(__FILE__)."/includes/builder/module/Blog.php";
this will cause the issue. to fix this there are two way:
#1: find and edit the file wich is call the blog template (not recommend)
#2: find and copy the file wich is call the blog template to your child theme (you can try with index.php, content.php or single.php first) (recommend)
Related
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.
I would like to modify a php file which is in "/inc/sections" folder of the Shop Isle theme (Wordpress) through a child theme. I tried the classic way by creating a new php file with the same name in my child theme but it s not working. I ve read there is a way to make the child file overriding the parent one using a function.
All what I ve tried didn t work or like this code below create some bugs (scrolling problem, blank space, etc):
<?php
require get_stylesheet_directory() . '/inc/sections/shop_isle_big_title_section.php' ;
?>
Do you know a solution ?
front-page.php code:
/* Wrapper start */
echo '<div class="main">';
$big_title = get_template_directory() . '/inc/sections/shop_isle_big_title_section.php';
load_template( apply_filters( 'shop-isle-subheader', $big_title ) );
Ok it s working now!!!
I just had to create a new front-page.php in my child theme and replace "template" of get_template_directory with "stylesheet" ...
Thanks for your help
I am getting my head around adding localizable strings to a wordpress child theme, and have not been able to do this successfully.
I have a child theme with a .php page to which I want to add a localizable string. In my child theme's functions.php, I have added the following line:
load_theme_textdomain( 'i-craft-child', get_template_directory() . '/languages' );
Next, using Loco Translate, I uploaded the files de_DE.po and de_DE.mo to the directory /languages within the child theme directory.
Finally, I added the following line to my html page:
<span><small>><?php _e( 'Your email address is also your username and it cannot be changed', 'i-craft-child' ); ?></small></span>
However, the span above is displayed in English (instead of German). I am not sure where in the localization process am I failing and would appreciate any pointers to solve this problem.
Make sure that your theme text-domain is included, you can use something like this (if file doesn't exists, it will break your site, so use it on test environment).
$loaded = load_child_theme_textdomain( 'i-craft-child', get_template_directory() . '/languages' );
if( ! $loaded ) {
echo 'Unable to load files';
die;
}
Also, did you specify WP_LANG in wp-config.php, like this?
define('WP_LANG', 'de_DE'); // for example
Following up on the pointer from unixarmy above, the problem was that the function load_child_theme_textdomain was not able to read the files, due to me using the function get_template_directory() as a parameter. get_template_directory() will return the path of the parent theme, not the child. Substituting that for get_stylesheet_directory() solved the problem.
I achieved that problem going to the Advanced configuration inside Loco:
Themes -> Child Theme Name -> Advanced.
Inside this area you can define the 'text domain' you will use when translating your theme, for example:
<?php _e('My string','generatepress-child'); ?>
Where generatepress-child is the text domain.
In my case the child theme and parent theme where merging on the same path (on the parent path) and loco wasn't able to 'fetch / scan' the strings inside the child theme, so I added manually the new child path inside this advanced section and now I can translate the strings inside my child theme.
After this I have had to add this lines on my functions.php parent theme:
function wpdocs_child_theme_setup() {
load_child_theme_textdomain( 'generatepress-child', get_stylesheet_directory() );
}
add_action( 'after_setup_theme', 'wpdocs_child_theme_setup' );
Hope it helps!
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
I can't work on any specific theme file like header.php, footer.php OR function.php within theme directory.
Reason is project always need new theme and theme is get changes in each week.
So I want something like that will work on each theme, no matter which theme admin applied.
I tried wp_enqueue_script() but again I need work on theme's function.php file.
The only way to do this is to run wp_enqueue_script() from outside of the theme (i.e. NOT in functions.php). The only way you can do that is to use a plugin.
See: http://codex.wordpress.org/Must_Use_Plugins
Or: http://codex.wordpress.org/Writing_a_Plugin
Create a plugin by adding a .php file in the /wp-content/plugins/ directory, or possibly even better for this situation create a 'must use' plugin by creating a .php file in the /wp-content/mu-plugins/ directory.
The structure of this .php file should be something like the following:
<?php
/*
Plugin Name: Example Plugin
Description: Any functions that should persist even if the theme changes.
Author: Your Name
Version: 1.0
Author URI: http://yoururl.com
*/
function my_scripts() {
wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );
}
add_action('wp_enqueue_scripts', 'my_scripts' );
?>
You need to write a plugin that rewrites theme's sections. A good start for creating a plugin is here. If your themes shares the same Javascript you could try to add your things to those Js.