Don’t print customizer styles when no setting has been used

There’s not really any trick, you need to check all the values. You can save a little space though, by omitting the != ”, which is redundant: if ( get_theme_mod( ‘myplugin_h2_color’ ) || get_theme_mod( ‘myplugin_h3_color’ ) || get_theme_mod( ‘myplugin_p_color’ ) || get_theme_mod( ‘myplugin_p_size’ ) ) { However, it’s possible to save Customiser settings into a … Read more

Using get_theme_mod in php ajax form doesn’t work

You should never access directly theme files, form submissions, ajax, and even just get requests will be blocked at the server level by some security hardening measure. Ignoring that for a moment, the reason your code fails is because wordpress wasn’t bootstrapped and therefor there are no core functions available. It is actually not 100% … Read more

Theme logo metadata into template file

Ends up that “alt” is not stored in wp_get_attachment_metadata so I pulled it from the post meta: $custom_logo_id = get_theme_mod(‘custom_logo’); if ($custom_logo_id) { $image = wp_get_attachment_image_src($custom_logo_id, ‘full’); $meta = wp_get_attachment_metadata($custom_logo_id); **$alt_text = get_post_meta($custom_logo_id, ‘_wp_attachment_image_alt’, true);** echo ‘<img src=”‘ . $image[0] . ‘” alt=”‘ . $alt_text . ‘” width=”‘ . $meta[‘width’] . ‘” height=”‘ . $meta[‘height’] … Read more

Progmatically adding menu links to the default (Top) or Footer menu

You have to register the menu location first. Also, I’ve added else statement to be sure $menu_id is defined when menu exists. Otherwise, you’ll see the PHP Notice about undefined variable. WP_DEBUG must be turned on when you develop, that’s why you don’t see the notice. // Initialize name and location $menu_name=”Simple Inventory Menu”; $menu_location … Read more