Normally the functions.php in your CHILD theme is called before the PARENT functions.php. In some cases, you might like to alter functionality loaded through the PARENT theme in your CHILD theme, which is not possible without some changes.
From the WordPress Codex :”Unlike style.css, the functions.php of a child theme does not override its counterpart from the parent. Instead, it is loaded in addition to the parent’s functions.php. (Specifically, it is loaded right before the parent’s file.)”
For our new setup, I am using a base class in our PARENT theme to define all our defaults. Some of the CHILD themes need to overwrite or adjust functionality. This allows to have a pure foundation, than alter and extend as needed.
PARENT functions.php
is extending the TimberSite class in my case, as I am using Timber (TWIG for WordPress) for my themes
class cubicFusionBase extends TimberSite { function __construct(){ parent::__construct(); } } // If no CHILD theme is loading init the parent class if(CHILD_THEME_LOADED != 1){ new cubicFusionBase(); }
CHILD functions.php
// Do not init the parent class // Wait for theme setup to be finished add_action( 'after_setup_theme', function() { // Extend parent theme class class cubicFusionChild extends cubicFusionBase { function __construct() { // Call parent class constructor parent::__construct(); } /* Add or extend any other functionality here */ } // Init Child class new cubicFusionChild(); }, 42 );
Cheers
Alex
What are particle animations? Particle network animations in JavaScript typically involve creating visual representations of… Read More
BOOKING SOLUTIONS 202x This is my take on a subset of booking, appointment, PMS or… Read More
THE GOAL Create a system cron for WordPress, that is accessible and can be easily… Read More
2024, what's cooking? Slowly getting into the 2024 spirit. 3 projects coming to a close… Read More
Short look back at 2023 This has been a busy and interesting year. I am… Read More
Elementor Pro provides grid containers as an experimental feature. The options provided are limited, when… Read More