- This topic has 6 replies, 2 voices, and was last updated 7 years, 12 months ago by Mahesh.
-
AuthorPosts
-
November 23, 2016 at 2:14 pm #103766MarkParticipant
Hi everyone, new Catch Themes user here and I’ve just bought Catch Base Pro after evaluating the free version for a week. Very pleased with the overall simplicity and customisability.
I would love to be able to change theme settings in a child theme’s functions.php file instead of doing it in the theme customizer. I have done this with another theme (Hueman) but I can’t work out how to do it in Catch Base.
Why would I want to do this anyway? I like to create a child theme on my testing server, get everything set up with the right theme options defined in functions.php and then deploy the theme instantly on the live website without needing to set all the options in the WordPress dashboard/customiser.
For example, I would like to set the featured content and slider to ‘disabled’ be default (but that’s only one of many settings I would like to set the default for).
I found the function catchbase_get_theme_options() which returns an array of all the theme option settings but couldn’t work out a way of setting them.
I also found the file inc/catchbase_default_options.php which I could use to set the theme defaults (but would not overide any changes actually made in the customiser) but modified versions of files in the child theme’s inc/ folder don’t seem to get applied – a general problem possibly?
I will continue to experiment with my knowledge of PHP but lesser knowledge of WordPress and child theme functions but any help would be appreciated.
This isn’t a show stopper right now but it would be great if I could create a function or something to change any setting in the child theme’s functions.php.
Mark.
November 23, 2016 at 3:49 pm #103775MarkParticipantQuick Update, I read somewhere else that files in the inc folder don’t get used in child themes and that you should simply take the functions from files in the inc folder and put them into your functions.php file.
So I did that with the catchbase_get_default_theme_options() function and that allows me to set all the defaults which **would** be good. However that function in the main (parent) theme does not seem to be child theme friendly – it doesn’t have the if !function_exists code around it. So I get ‘Cannot redeclare….’ errors.
November 23, 2016 at 5:04 pm #103779MaheshParticipant@improdia: In some functions,
function_exists
is used, that’s why the error is occurring. The solution is, make a new function then remove the previous function withremove_action
and hook up the new function withadd_action
.
Hope you understand.Regards,
MaheshNovember 23, 2016 at 6:07 pm #103782MarkParticipantThanks for that Mahesh. I sort of understand what you mean – I’ve seen similar solutions for other requirements in child themes but on this occasion, the functions I’m looking at are
catchbase_get_default_theme_options
andcatchbase_get_theme_options
(which calls the first one). Neither of these are added as actions anywhere andcatchbase_get_theme_options
is just called from within many other functions that need to access the theme’s options values using something like$options=catchbase_get_theme_options()
So please correct me if I am wrong (I hope I am!) but I don’t see how I can use remove_action for
catchbase_get_default_theme_options
orcatchbase_get_theme_options
in order to replace them usingadd_action
November 24, 2016 at 12:19 pm #103820MaheshParticipant@improdia: These functions are for getting default values or assigning values. Its not like the other that is called to be executed with add_actions. By the way, why do you want to override these two functions?
Regards,
MaheshNovember 24, 2016 at 1:18 pm #103828MarkParticipantPerhaps I need to simplify this!
The reason I would want to override the
catchbase_get_default_theme_options
function is because I want to have my own set of default theme options for my child theme.I don’t see anyway to change the default values with a function as they are hard coded into the existing function
catchbase_get_default_theme_options
. I think I have now realised that what I want to do is not possible because:a) The files inside the inc folder of the child theme do not override the parent theme
b) The existing functioncatchbase_get_default_theme_options
is not child theme readyIt’s not really a problem just an inconvenience!
November 24, 2016 at 3:28 pm #103839 -
AuthorPosts
- The topic ‘Programmatically change theme options in child theme’ is closed to new replies.