I’m developing a theme which uses the NHP Theme Options Framework to add some theme options. Naturally, the theme options framework creates a single row in the database to store the theme’s options into.
If I create a child theme of the parent, it shares the same theme options as the parent, which leads me to my question:
Should a child theme share the same theme options row as the parent, or should it have it’s own options row? Is there a reason why one would be better than the other?
If they are shared and you switched between the two themes, your options would be intact. This can be great if that was the intended behavior. On the other hand, you might go to great lengths to customize the child theme thinking it’s independent, switch back to the parent and find your changes overridden. I’m having a hard time choosing one over the other. What are your thoughts?
Neither.
Theme options should be stored as theme mods, using
get_theme_mod
andset_theme_mod
.Internally these map on to options, but it is the official way to store theme specific options, that way when you change themes you don’t get clashes, and your settings are preserved for if you ever change back. It’s the classic adage of “someone else solved that problem for me, it’s their problem now”
But should you persist in using options, I would advise you prefix all your options with your theme name, and not to share options between child and parent. Setting a child themes options should not affect a site when moving back to a parent theme.
There may be cases when it is advantageous though, so exercise good judgement ( aka use
set/get_theme_mod
)You can find more about this API here