I am currently working on a WordPress website, which has a Parent and Child Theme.
The Parent Theme is outputting the following statement, at the top of the WordPress Dashboard:
This theme requires the following plugins: Plugin A, Plugin B, Plugin C etc
Triggering this output, is the following code, within the Parent Theme's functions.php file:
require_once get_template_directory() . '/inc/plugins/class-tgm-plugin-activation.php';
Is there a way I could disable this, via the Child Theme's functions.php? Sure, I could comment it out within the Parent Theme, but this could get overridden during a future update. I did try to copy the entry, into the Child Theme's functions.php, then comment it out there, but that did not work.
Latest Effort
I went into the WordPress Dashboard, where I copied the notification message prefix:
This theme requires the following plugins:
I then went into the file located within get_template_directory() . '/inc/plugins/class-tgm-plugin-activation.php', where I found the above notification prefix, located within the do_action( 'tgmpa_register' ); function.
I then located the add_action for the do_action( 'tgmpa_register' ); within the /inc/functions/tgm-functions.php directory.
I then headed into the Child Theme, and duplicated the above folder hierarchy.
I then commented out both add_action and do_action, within their respective files as well as entering remove_action( 'tgmpa_register', 'register_required_plugins', 999 ); into the Child's functions.php file.
Unfortunately, neither of the above work. I take it, that this is because the Parent Directory parent_theme/inc has priority over the Child Directory child_theme/inc? If so, is there a way to change this?
Related
There's a bunch of css in my parent theme I don't need and instead of just overwriting it all, I'd like to dequeue it completely and put most of the CSS from the parent theme into the child themes css file.
Is this possible?
First you'll need to identify the names/handles that the parent theme's stylesheets were originally enqueued under. You can do this quickly by running a search on your web server in the parent theme directory, e.g. grep wp_enqueue_style /var/www/mysite/wp-content/themes/parent_theme/
Then add a dequeue function to the child theme's functions.php file, and initialize it with a priority higher than the priority level set for the parent theme's enqueue function:
function remove_parent_styles() {
wp_dequeue_style( 'name_of_parent_stylesheet' );
wp_dequeue_style( 'name_of_parent_stylesheet_2' );
}
add_action( 'init', 'remove_parent_styles', 99 );
You should identify your styles/scripts handle name before dequeue it. A easiest way is install Query Monitor plugin and see in Styles tab. Handle name is in second column.
With this plugin, you also see CSS files are required by any dependants.
Dequeue your CSS:
Append this code to the end of your theme's functions.php file:
function tdt_dequeue_styles(){
wp_dequeue_style('your-handle-name');
wp_deregister_style('your-handle-name');
// Another style dequeue
wp_dequeue_style('your-2nd-handle-name');
wp_deregister_style('your-2nd-handle-name');
}
add_action( 'wp_print_styles', 'tdt_dequeue_styles', 9999 );
I'm trying to make changes to a WordPress theme via FTP, and it doesn't appear to update on the live website.
In this case I made changes to a JavaScript file:
../wp-content/themes/Divi/includes/builder/scripts/frontend-builder-global-functions.js
Currently a child version of the theme is active on the site. Is there a process I'm missing to have my live website reflect the changes? Also, in Chrome developer tools, the file I tried to update has ?ver=3.17.6 at the end of the filename.
The easiest way would be to copy the updated JavaScript file from the parent into the child theme's folder, next in your child theme functions.php file use the built in WordPress functions wp_deregister_script and wp_register_script. Your code should be like this:
function new_child_script() {
// De-register the Divi default theme script
wp_deregister_script('frontend-builder-global'); //check the name of the default script in page source
// Register the updated script from the child theme
wp_register_script('frontend-builder-global-custom-script', get_template_directory_uri() . '/js/frontend-builder-global-functions.js',
array('jquery'));
// Enqueue the script
wp_enqueue_script('frontend-builder-global-custom-script');
}
add_action('wp_enqueue_scripts', 'new_child_script');
I'm having issue in overwriting parent theme file via child theme. Normally I copy parent theme file to child theme by following same file structure/path and it works. But this time it is not working. I'm not sure, what is the problem...
The parent file is located at:
wp-content/themes/THEMENAME/assets/js/FILENAME.js
and I put at this path in child theme:
wp-content/themes/CHILDTHEME/assets/js/FILENAME.js
Same problem on this file:
Parent Path:
wp-content/themes/THEMENAME/includes/FILE.php
Child Path:
wp-content/themes/CHILDTHEME/includes/FILE.php
I'm pretty sure, I'm missing something technical but I'm unable to figure out. Looking for help!
Child theme doesn't override css/js files, to achieve that, You will need to dequeue these scripts in the child functions.php file, You need to get the script handle name that parent theme uses to enqueue it.
add_action( 'wp_enqueue_scripts', function(){
wp_dequeue_script( 'script-handle-name' );
}, PHP_INT_MAX );
Child theme only overrides the template files Template Hirarchy
To override a php file, There are two conditions:
1) If the file function you want to override is hooked to action / filter then create a function in the child theme functions.php file with a different name and hook it with a higher priority.
2) If you want to override the function itself, you can recreate the function in the child theme functions.php with the same name only if The function is created in the parent theme with the condition.
if ( ! function_exists ( 'my_function' ) ) {
function my_function() {
}
}
otherwise, It will raise a fatal error.
I've created child themes before without issue however when I create one using Woocommerce Mystile theme it does not display properly with menu items missing and images resizing to be too large.
I made the child theme by creating a new folder in the wp-content>themes folder called mystile-child and creating style.css with the contents
/*
Theme Name: Mystile Child
Description: Mystile Child Theme
Template: mystile
*/
I then created a functions.php file with the contents
<?php
add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
function enqueue_parent_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
}
?>
this is what the parent theme looks like:
This what the child theme looks like
Just out of curiousity - were the logo and other missing elements set up intially using the theme customizer (reached via the wordpress admin menu Appearance > Customize)?
If that's the case, then those settings are created outside of your theme and need to be reset or imported for your child theme. There are a few ways to accomplish this, the easiest way being with a plugin which imports/exports those Customizer settings.
Hope that helps,
Laura
Okay I fixed the problem following the advice found on Wordpress.org support forum here https://wordpress.org/support/topic/mystile-theme-child-header-problem
Seems more of temporary fix though and something that the people at Woocommerce should investigate.
I've created a Wordpress child theme and now want to remove the widgets from the sidebar. However all the tutorials are not helping.
Each one says to add the following code to my functions.php file in my child theme:
<?php
function unregister_old_sidebars() {
unregister_sidebar('sidebar-1');
}
add_action( 'widgets_init', 'unregister_old_sidebars' );
?>
However, do I copy the entire functions file from the parent theme and copy it in a new functions.php in my child theme, or is this the ONLY code that I put into my child theme functions.php file.
Nothing I do seems to be working.