1

At theme customization, the values from the 'default' attributes, which I added when calling the add_seting() method within the functions.php, are properly filled in. They are not filled into the db though. Is that the normal behaviour?

I thought it would be kind of an initial setup for the theme. In my case, the get_theme_mod() methods are not getting any values (because there are no in the db). I would have to fill all the defaults again as the second parameter for get_theme_mod().

Any clues what I'm doing wrong?

  • Right, the default value was not saved in the database. The method $wp_customize->get_setting() get this default value, if is no value inside the database. Important is, that you register the key for your value via customize_register. – bueltge Jan 6 '15 at 9:22
  • But I don't have the $wp_customize object within header.php etc., right? So how can I build the theme based on the default values without putting them into the get_theme_mod method? That would be annoying and redundant. – Wipster Jan 6 '15 at 9:39
  • get_theme_mod() is a simpler alternative to the settings API when there is a need to handle basic theme-specific settings, that you use via the customizer and you can set values for this function with set_theme_mod(). – bueltge Jan 6 '15 at 10:19
  • Okay, I think it is not clear what the problem is here. In footer.php I use get_theme_mod() without the default parameter because the defaults are already set within the add_setting() method. I thought, after activating the theme, the defaults get written into the db. They don't. So some parts of the theme are not showing, because get_theme_mod returns nothing. How do I make the defaults get into the db after activating the theme? Wiered enough the defaults are actually filled into the theme customizer form. When changing them, they get written into the db. – Wipster Jan 6 '15 at 10:27
  • You can only set the values for get_theme_mod() with help of set_theme_mod() or you create a function on setup the theme, that you write the values in the database, if not exist. But this is not really fine. The values are not helpful in the database and it costs performance. – bueltge Jan 6 '15 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.