February 28, 2016 at 9:57 am
Hi Ben,
I need a custom page for bookings and created a childtheme of Virtue-Premium with special versions of
*- virtue_premium/page.php to mychildtheme/page-bookings.php for the content part
*- virtue_premium/base.php to mychildtheme/base-page-bookings.php for the whole HTML frame
That works fine, but …
The booking part gets only 9/12 width, leaving 3/12 to a sidebar, which I don’t want here.
So I see there is a function in virtue_premium/lib/config.php
function kadence_display_sidebar() {….}
defining all standard theme page-template names for fullwidth pages
I want to override this function with my version including mine: ‘base-page-bookings’
So I put a special version of function kadence_display_sidebar() in my childtheme
That gives an ugly Fatal Error: you can’t redeclare functions in php
WordPress in some core functions has a workaround, see wp-includes/pluggable.php
wrapping the function between the lines if: … endif:
if ( !function_exists(‘kadence_display_sidebar’) ) :
function kadence_display_sidebar() {….}
endif;
The function is loaded with the childtheme, and if so the theme does not try to redeclare the same one.
I tried that and it works.
But I am changing a theme file, which is bad practice and will last only to the next theme update.
It should better be done within the theme, if you agree.
A few inquieries:
1- Has Virtue a better solución for this?
2- Is it possible to make this change for this function, and maybe others, in the theme,
to allow childthemes override functions and hence have a more adaptable theme?
3- Do you think this change may affect in some way other things?
4- Do you have documentation for this, not childthemes in general, but specific hints for your theme
Which files to change, location of the file, aplicable links to codex …
I googled a bit, most people say: you can’t redeclare functions in PHP, but this link gave me the hint:
*Login to see link
Best regards,
Hugo