Tag Info

Hot answers tagged

12

The premise of the question is flawed. The Customizer API is not an options API, but rather an options preview API. The Customizer API relies on either the Settings API or the Theme Mods API to register controls for existing settings added via either of the two APIs. The Customizer does not - and cannot - define/register new settings that have not already ...


9

There's a few bits here that apply, but the short of it is this code in customize-preview.js: this.body.on( 'click.preview', 'a', function( event ) { event.preventDefault(); self.send( 'scroll', 0 ); self.send( 'url', $(this).prop('href') ); }); The event.preventDefault prevents the links from actually working. The following code then sends a ...


9

Our journey starts here with the WP_Customize_Background_Image_Control class, which is a WP_Customize_Image_Control. I'd imagine offering these built-in backgrounds in a new tab alongside the existing Upload New and Uploaded tabs. There are at least two ways of achieving the following: either creating your own modified class based off of the ...


8

Example and class for usage You can see on my current theme, how it's possible to use this. Also you can usage the class. See this class on Github an check the functions.php for include this. Start & init You can register your custom settings for the theme customizer via the customize_register hook: add_action( 'customize_register', ...


8

This drove me mad for a while, but I got it to work by adding them with the full arguments that are used in the admin script loader rather than just referencing the handle. When I print the $wp_scripts global on the front end, iris and wp-color-picker are nowhere to be found, though all of their jQuery UI dependencies work. Anyway, not sure this is right, ...


5

If you need them in a specific order, then give a priority value to the controls. Otherwise, their order is not defined and cannot be guaranteed. If you don't define a priority, then the control gets the default priority of "10". When two controls have the same priority, then the resulting order is undefined, because that's how PHP works.


4

Here is one way to do it by extending the control you want to use. Below is an example where we extend the text control and add an extra description like the one seen here on the screenshot: function mytheme_customizer( $wp_customize ) { class Custom_Text_Control extends WP_Customize_Control { public $type = 'customtext'; public ...


4

Okay, first, let's set things up properly, with a callback hooked into an appropriate action hook: <?php function wpse55227_enqueue_scripts() { // Enqueue code goes here } add_action( 'wp_head', 'wpse55227_enqueue_scripts' ); ?> We'll put all of our code in to this callback. The next step is to add our if ( ! is_admin() ) conditional wrapper: ...


4

As simple as things can sometimes be: The Settings API is not the Theme Customizer. Both are different things for different tasks. Settings API You're either writing a plugin or have a theme that doesn't have options that won't need any visual feedback? Go with this option. Theme Customizer You need to have options that have a visual impact that the user ...


3

You're never using your class. Try passing a new instance of your class to the add_control method: $control_args = array( // your args here ); $my_control = new WP_Customize_Palette_Control( $wp_customize, 'themename_color_scheme', $control_args); $wp_customize->add_control($my_control); Also, I don't think WP knows that the option ...


3

As in this question: How to execute conditional script when on new customize.php (Theme Customize) screen global $wp_customize; if ( isset( $wp_customize ) ) { // do stuff }


3

I found out the WP_Customize_Manager class has a function called remove_section(). In your function hooked to customize_register you can just do: $wp_customize->remove_section('nav'); $wp_customize->remove_section('static_front_page'); You can find the ID of the section (i.e. 'nav') if you inspect the accordion title bar of the section. Look ...


2

It appears that 'customize_controls_enqueue_scripts' also works and may be the intended function. function theme_customize_style() { wp_enqueue_style('customize-styles', get_template_directory_uri() . '/customize.css'); } add_action( 'customize_controls_enqueue_scripts', 'theme_customize_style' );


2

Ok, here's how to do this. Seperate your control class(es) to one or more new files. You have a function or method hooked on customize_register, right? In that function or method require once your new files just before adding your custom controls. Then PHP won't complain about redefining classes. Note: This will not work out of the box, but shows the ...


2

If your settings are stored as Theme Mods, rather than as a Settings API option, then you need to pass the appropriate value to the type parameter to $wp_customize->add_setting(): 'option': Settings API option (get_option()) 'theme_mod': Theme Mods API option (get_theme_mod()) Try changing this: $wp_customize->add_setting( $this_theme . ...


2

The color picker thing is registered as a jQuery UI widget, so you could modify its prototype object before the widget is used in the page: add_action('customize_controls_print_footer_scripts', function(){ ?> <script> jQuery(document).ready(function($){ $.wp.wpColorPicker.prototype.options = { border: false, // ...


2

Not sure what you try to accomplish, but you can get a value by key using the wp.customize object: wp.customize.value('show_on_front')(); wp.customize.value('blogname')(); .... sorry no jQuery here, just javascript, and yes, the extra () are intentional. Edit: Full overview of all settings: wp.customize._value; console.log(wp.customize._value); Edit ...


2

If you need a specific ordering of the input fields, then add "priority" values to the controls in the add_control calls, same as you already have for the sections. If you don't have a priority, then no particular order is guaranteed and you get whatever PHP happens to order your arrays as.


2

The issue in this case has to do with how I added the customize.php script. I was loading it inside an is_admin() check (see updated question above where I have included that code branch). After reading Otto's post, I realized that the customizer hook does not fire in this context.


2

Couple points: The customize_register action hook actually passes your function the $wp_customize variable, you don't need to declare it as the global. Just put it as the first argument in your function declaration. The reason your code doesn't run on the front end of the site is that the customize_register action hook only runs when the customizer is ...


2

Got it! Here's the code that worked for me. -- Theme Customizer settings and controls (mine are in a separate customizer.php file): function themename_customize_register( $wp_customize ) { ... $wpcustomize->add_setting( 'themename_skin', array( 'default' => 'light', ), ); $wp_customize->add_control( ...


2

Accoring to OTTO One final thing you can add to a section is a “theme_supports” option. This will make the menu not appear unless the theme supports something. If you’re putting this code in a theme itself, then you already know what the theme supports, so it doesn’t make much sense. The core uses this to not show the header and background ...


1

Your description makes it sound like you need a radio button. Radio buttons by design are exclusive-- only one button per button set can be checked at any one time. The Settings API supports radio boxes, though the documentation for using them is sparse. I had to dig around a bit, and experiment. The key is the second parameter of add_control. You need to ...


1

I would comment if able. If your theme variations consist solely of style modifications you can add the variation stylesheets @ inc/css/ and then here is an example of the references to make it all tick. @ \options\options-core.php: $fields_list[] = array( 'name' => __('Select a Skin Color', 'mytheme'), 'id' => 'mytheme_skin_color', ...


1

This is not a complete solution and the code is not tested, but I it should be enough to give you a general idea of how to use the customizer for different pages. // Add "Edit page with customizer" link to relevant pages add_action('admin_bar_menu', function($bar) { if (is_home()) { $bar->add_node(array( 'id' => 'some-id-1', ...


1

here is the code i am tring to make it work. 1. here i am tring to pull out the selected opsion. but this not working. evry time the user choose some student name and click the save button the selected opsion returns to be default opsion. 2. i have create class to insert this drop down menu to Theme Customizer section but it not working and i get php ...


1

If I understand you goal correctly, then will you a select inside the Customizer, there list the Categories and the User can use this for save in your theme settings. If you will enhance the Customizer for categories, then use this class from this repo here. Include the file and enhacne the default class. You can easy implement a select for the categories ...


1

My answer might come a bit late for you, but as I had the same problem today, here's what I found out: 1) First of all, if you set 'type' => 'option' for your custom settings, you should use the get_option() function to retrieve the values. If you set 'type' => 'theme_mod' (or don't set a type at all as it defaults to theme_mod), you can retrieve the ...


1

Most WordPress functions that echo a result have sister function that return the result. To find them, go to the the Codex reference page for the function you are using. For this function, search Google with this phrase: site:codex.wordpress.org the_post_thumbnail Click on the link to the function then on the Related section and you will find other ...


1

However, the recommended mechanism for injecting the styles is really not cool. All guides I've read online and from Wordpress recommend they be added inline to the Head of the document. That's how HTML works, no fault of WP's. Dynamic stylesheets have always been a challenge since CSS is not dynamic language by nature. There is number of options, ...



Only top voted, non community-wiki answers of a minimum length are eligible