Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to save options for a specific category in the WordPress Customizer?

Tags:

php

wordpress

I am using the WordPress Customizer and I'd like to add options for categories, for instance "category background image", and so in the Customizer you go on Category X in the preview, you then set the category background option to be "red", and you then navigate to Category Y in the preview, and using the same option you can set it to be "blue" for this particular category. And the idea is you could do this with unlimited categories, so they can all have different background colors.

Is this possible? I know you can use the active_callback to make options in the customizer itself appear/disappear depending on where you are (i.e on a category page), but can you make options save an array with the current category ID seen in the preview + a value?

like image 843
capvidel Avatar asked Sep 09 '16 14:09

capvidel


1 Answers

You could add all your options and use the active_callback parameter on the parent sections. In your active_callback function you could have something like return(is_category(Category ID, name, slug, or array of Category IDs, names, and/or slugs)).

like image 105
Jonathan Avatar answered Oct 21 '22 21:10

Jonathan