Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #103766
    Mark
    Participant

    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.

    #103775
    Mark
    Participant

    Quick 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.

    #103779
    Mahesh
    Participant

    @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 with remove_action and hook up the new function with add_action.
    Hope you understand.

    Regards,
    Mahesh

    #103782
    Mark
    Participant

    Thanks 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 and catchbase_get_theme_options (which calls the first one). Neither of these are added as actions anywhere and catchbase_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 or catchbase_get_theme_options in order to replace them using add_action

    #103820
    Mahesh
    Participant

    @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,
    Mahesh

    #103828
    Mark
    Participant

    Perhaps 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 function catchbase_get_default_theme_options is not child theme ready

    It’s not really a problem just an inconvenience!

    #103839
    Mahesh
    Participant

    @improdia: Overriding this function may create problem and the theme may not perform as it should. As the functionality problem will occur, this is not possible.

    Regards,
    Mahesh

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Programmatically change theme options in child theme’ is closed to new replies.