WordPress.org

Forums

Editor
[resolved] Poor child-theme support? (6 posts)

  1. andrewcrook
    Member
    Posted 9 months ago #

    G'day

    I'm doing a bit of customizing using a child theme, but I've run into a roadblock.

    I've modified the Customizer options in /inc/customizer.php, but the child theme version of the file isn't being called. It's still using the file in the parent theme because of the call

    require get_template_directory() . '/inc/customizer.php';

    As far as I know, it's not possible to 'unrequire' a file and replace it with the child version. This can be fixed by changing this line in the parent theme to

    require get_stylesheet_directory() . '/inc/customizer.php';

    We obviously don't want to change the parent theme, as they'll be lost when the theme updates.

    I'm hoping the developer will be able to make this change in the next update to allow for better child-theme support.

    Is there any other way to achieve this by not editing the parent them?

    Thanks!

  2. BabyFaceWeb
    Member
    Posted 9 months ago #

    Hi Andrew,
    normally to modify a core template php file like that, one needs to unhook the original function via the child theme's functions.php and THEN add back your new modified version of the function.

    An alternative way is that you can modify (in some cases) the name of the function that is being called in your child theme template files and then create a duplicate of the original theme's php customizer with a NEW function name, that you call in your modified child theme template (essentially leaving the original function and php code alone)

    If I've misunderstood your question, feel free to elaborate so I can try to help further ;-)

    Best!
    Steve

  3. mindctrl
    Member
    Posted 9 months ago #

    If we used get_stylesheet_directory in the parent theme, and someone created a child theme but did not provide a /inc/customizer.php file in their child theme, it would give them a white screen and their site would crash because the required file would be missing in the child theme. Using include instead of require would prevent the white screen, but simply would not load the one from the parent theme.

    There are other workarounds, like locate_template, but we chose to stick with the recommendations from WordPress.com since we're also submitting the theme there for inclusion in their theme directory.

    If you want to extend the customizer options with your own, you could just include those in your child theme's functions.php and let both the parent and the child load their customizer options. You could also unhook the Editor customizer functions, using something like remove_action( 'customize_register', 'editor_customizer_register' ); and add your own.

  4. andrewcrook
    Member
    Posted 9 months ago #

    Thanks BabyFaceWeb and mindctri, I'll try your suggestions and let you know how I go!

  5. andrewcrook
    Member
    Posted 9 months ago #

    Thanks mindctri

    I took your advice and added my own customizations to a new function, which appended my fields to the customizer, as I only wanted to add (not remove) fields. I followed this tutorial for tips: http://code.tutsplus.com/tutorials/a-guide-to-the-wordpress-theme-customizer-adding-a-new-setting--wp-33180

  6. BabyFaceWeb
    Member
    Posted 8 months ago #

    Nice Job Andrew!

Reply

You must log in to post.

About this Theme

About this Topic

Tags

No tags yet.