0

I've cast a pretty wide net to find an answer but nothing seems to quite hit the mark.

Process:: I Login to my site/dashboard and I decide I need to edit a portion of my theme through the customiser, so I do, pretty straight forward...

In the mean time, I've built up my child theme and it seems to work pretty well for a novice and have generally figured out how to duplicate and edit particular .php files such as the footer, header etc... and, change (template to stylesheet) to load child theme images; however!

I wanted to change the social media links in my footer and had to scratch my head for a fews before figuring out how the customiser works and where the .php files are stored so I could change and add new fab fa.icons icon.

Problem:: my child theme function.php is doing what it needs to be doing, likewise with my pages, and is safeguarded form theme updates, however! not my new "customeriser" changes, so I have to go back in and change them time over...

I have found the location of the directory for the customiser, hence the ability to edit it, but to safeguard it from being changed is another thing.

The customiser files are duplicated to the child directory, then I load (along with tried variations of include, stylesheet, url)

require get_template_directory() . '/inc/business-prime-customizer.php'; 

it crashes my site...

So how do I point my child function.php at that new customiser address/files?

Many thanks and greatly appreciated

John

  • See my answer to a similar question here: wordpress.stackexchange.com/a/309845/39152 The short version is that you can't just copy any old file from a theme into a child theme and replace it. If there's other PHP files that you want to replace, you'll need to use remove_filter() and remove_action() to un-hook any functionality that they add. – Jacob Peattie Jun 22 at 12:37
  • Hi Jacob. Is this similar or the same as Chetans answer below? More so as his suggestion gets me half towards and independent (Child) customizer, but I have to manually block out #require get_template_directory() . '/inc/business-prime-customizer.php'; within the parent customizer for it to work? – Shadow Crown Jun 22 at 15:43
  • Chetan's answer is a specific example of the sort of thing you'll need to do, but the specifics depend on the actual theme. You shouldn't modify the parent theme at all. You just need to remove any hooks that are included in it from within the child theme. – Jacob Peattie Jun 22 at 16:10
  • Absolutely, otherwise what is the point to the child theme... don't get me wrong, I've implemented both your codes, and to the letter, as a yardstick test and both codes yeild results; but I still have to force the parent function.php file by manually removing the require function. Basically it's not dequeueing automatically and permentally like any other functions? – Shadow Crown Jun 22 at 19:01
  • You can’t un-require files from a parent theme. – Jacob Peattie Jun 22 at 19:30
0

First remove action of customizer then add your action with new function name.

in your child-theme functions.php

add_action( 'init', 'remove_my_action');
function remove_my_action() {
     remove_action('customize_register', 'business_prime_settings_control',10);
}
require_once dirname( __FILE__ ) . '/inc/business-prime-customizer.php';

in your child-theme/inc/business-prime-customizer.php change name of function and callback

function business_prime_settings_control_child($wp_customize) {
    # here your all customizer settings code
}
add_action('customize_register', 'business_prime_settings_control_child');

Remove other extra actions and declared functions. otherwise you will get : Cannot redeclare Fatal error.

  • Hi Chetan, thanks for your reply, I found all the functions you pointed out in your code and followed to the letter... - I've inserted the functions.php element on the end of my 'prime_child_enqueue_styles()' - Then inserted the rest replacing the original in my child version of business-prime-customizer.php However, i still get "The site is experiencing technical difficulties." Along with the other files, will having a business-prime-functions.php file not being addressed too, cause a problem? – Shadow Crown Jun 22 at 15:26
  • Ah Ha, back on line again!! I had to block out:: #require get_template_directory() . '/inc/business-prime-customizer.php'; code within the parent customizer for it to work... While this is the case; it is kinda of a smaller patch and may still revert back on an update?? – Shadow Crown Jun 22 at 15:36
  • yeah, it will revert back on an update. but you don't have to need customize in parent theme. just remove an action which is called by customizer_register in parent theme like i give an example above code. – Chetan Vaghela Jun 22 at 18:45
  • Absolutely, I followed your coding to the letter and once i've edited the parent function.php, then your code works perfectly and I can tell based on the differences; but i'm still editing the parent file as the child file is still not actually dequeueing it. – Shadow Crown Jun 22 at 18:56
  • ...along with your coding, any other suggestions as to triggering an automatic/permenant dequeue, like the rest of the styles in my child function.php file? – Shadow Crown Jun 22 at 19:07
0

Just wanted to say thank you for your feedback it has, and without a boubt, been very helpful. Otherwise, one answer and its results have been better than the other.

Just a little feedback of my own explorations...

After exploring the net, there does seem to be a slight gap in undersatanding these things, more so referring to us novices/amatures and our questions, equally so, when the answers can be somewhat long and not to the point, so thanks for your patience there.

Child theme creations seem to be quite the moot subject and, based on the parent theme, difficult to ensure they work properly. Therefore, based on your patience and obvious abilities, need to keep working at it, as such I'll keep exploring.

I'm kind of thinking that the answers are within the development process of creating the parent themes itselves, if I choose to invest that much time and money into it, or commission someone. So what worked and yielded a greater result:

As expected and to reduce the impact on the parent files, I duplicated the required parent files into the child theme, then as per advice added the following with a few tweaks.

Child functions.php::

    add_action( 'init', 'remove_my_customizer');
    function remove_my_customizer() {
        remove_action('customize_register', 'business_prime_settings_control',100);
    }
        require_once dirname( __FILE__ ) . '/inc/business-prime-customizer.php';

    add_action( 'business_prime_settings_control_child', 'business_prime_child_customizer',10);

Based on other opinions, my parent theme, and to increase stability, I added the additional add action as a forced loop element. Then I replaced the necessary elements in the new child copy of the customizer::

    function business_prime_settings_control_child($wp_customize) {
        # child.php customizer settings code
    }
    add_action('customize_register', 'business_prime_settings_control_child');

This approach yielded the better result as none of my customizer tabs, coding or functions, where lost and it removed particular parent theme marketing banners.

This approach also worked for inc/functions.php file too::

    add_action( 'init', 'remove_my_functions');
    function remove_my_functions() {
        remove_action('functions_register', 'business_prime_functions',100);
}
        require_once dirname( __FILE__ ) . '/inc/business-prime-functions.php';

    add_action( 'business_prime_functions_child', 'business_prime_child_functions',10);

However, the aspect I was talking about being a "95% resolve" was surrounding the parent main functions.php file::

    #require get_template_directory() . '/inc/business-prime-customizer.php';
    #require get_template_directory() . '/inc/business-prime-functions.php';
    require get_template_directory() . '/inc/business-prime-sanitize-cb.php';

Because the child theme functions is not overriding the hierarchy of the parent theme, out of the nine inc/parent.php files in the directory, I had to manually block out the two necessary ones to force the code to work; which I guess I will have to do again on the next update.

Once again, thank you for time and you've been a great helping hand, keep up the good work.

Kind Regards, John

-1

This should load the file from the child theme.

require get_stylesheet_directory() . '/inc/business-prime-customizer.php';

you should also set WP_DEBUG variable to true in wp-config.php file

if you want to load any file from the parent theme then you will use

require get_template_directory() . '/path_to_the_file.php';
or
require get_template_directory_uri() . '/path_to_the_css_file.css';

if you want to load file from the current child theme or active theme.

require get_stylesheet_directory() . '/path_to_the_file.php';
or
require get_stylesheet_directory_uri() . '/path_to_the_css_file.css';
  • Thanks for your reply Mobeen, unfortunately, I thought the same from my explorations, but no variation of that instruction works "The site is experiencing technical difficulties." – Shadow Crown Jun 22 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.