Adding an action will fire the function regardless, but you can add an if statement to see if the value has been set. This way the tag will not fire if the value is not set
function chrome_theme_meta() {
$chrome_theme = get_theme_mod( 'chrome_theme', '' );
if(!empty($chrome_theme){//test to see if a value is set
echo '<meta name="theme-color" content="', get_theme_mod( 'chrome_theme', '' ), '">';
}
}
add_action('wp_head', 'chrome_theme_meta');
Alternately, the second (empty) parameter of get_theme_mod( 'chrome_theme', '' ) is a fallback, so you could assign a default value if the setting has not been set.
Related Posts:
- Need help setting default setting value for radio button in theme customizer
- Is it possible to get a theme customizer setting from wp.customize using jquery?
- Dynamically change feature image in customiser
- One button to change all settings in theme customizer?
- Design view breaking on Pages
- How to add default images into theme customizer image control?
- Return a numerical function value in Customizer controls
- Skt full width basic slideshow problem
- Please show me how to use an if/else statement in combination with wp_enqueue
- get_theme_mod outputs number when using WP_Customize_Cropped_Image_Control
- Use SCSSPHP to compile Theme Customizer Values into .SCSS files ready to compile to CSS
- Need advice on theme customizer and child themes
- Getting text from custom field from customizer
- require get_template_directory() . ‘path/to-my/file.php’ BREAKS customize > themes functionality
- Using get_theme_mod with checkbox to display content
- How to add button to top of theme customizer?
- How can I clear the theme mod settings?
- Cant get theme to change footer color through theme customizer
- Cleaning up WordPress to improve performance?
- How can I modify the permalink via a filter?
- wp_set_object_terms and arrays
- How to get the original price of the product in woocommerce?
- How to use WordPress (PHP) functions in AngularJS partials files?
- The best way to customize “nav-menu-template.php” to add if the ‘link_before’ is “checkbox”
- How to add 2 posts under another post? Formatting should be intact
- enqueue multiple Google fonts with multiple weights and styles (italic)
- What is the fastest way to load PHP functions that are only used in one theme template?
- Can’t load WP function into external function
- Count top level menu items
- Image as Sales Badge
- add_action shortcut?
- WSoD being caused by this piece of code
- How to Arrange PHP Files to Allow for Multiple Types of Pages?
- How to complete two other input fields, completed the first
- Retrieve $_POST data submitted from external URL in WordPress(NOT API)
- Function to capture a value and store it in a variable
- Checking array against author id in loop
- Compare the old get_theme_mod($name) to the new get_theme_mod($name) return value
- Scrape external webpage for first image and add it to new post
- Trying to retrieve post meta
- Need help enqueueing webfonts
- Error call_user_func_array() expects parameter 1 to be a valid callback when using image_size_names_choose
- Tell WP register script to load a script only when the entire page is loaded
- Can’t save php string to a custom field
- Limit Taxonomy Output in Conditional Statement
- get_template_directory adding FTP root folders in urls
- Fatal error: Call to undefined function register_new_user()
- How to modify the default feed via a function
- Loop over Array and get the distinct ids
- How do I change this function from two returns to one string to show sku and dimensions in WooCommerce cart?
- Changing the order of custom fields in the dashboard for Woocommerce variable products [closed]
- Post not populating for custom post type based on category selection
- call_user_func_array() expects parameter 1 to be a valid callback, function ‘———-‘ not found or invalid function name
- How to remove the space before the ellipsis in excerpt?
- Dynamic Menu drops pages?
- Aspx/Rss feed – failed to open stream: Redirection limit reached
- Adding an Unlinked Space in a Custom Function
- How do I call an external php non WordPress class into functions.php?
- send popup after wp_redirect()
- Can/should we delete wordpress cron jobs with no action?
- Database entry removed on browser refresh, Ajax PHP jQuery
- Checkbox doesn’t save inside metabox
- A function to get the content of a page
- Display Visual Composer shortcode if a post belongs in specific categories
- Add Featured Image to Existing Post
- How to get latest post ID in functions.php?
- Billing detail page doesn’t work after I’ve changed the order of the Woocommerce navigation
- How can I prevent a shortcode div from extending beyond its boundaries?
- Advance custom fields variable with if statement & Function
- Restrict wordpress access to logged users only
- Change CSS Variable value in Theme Customizer Live Preview
- Get user by meta data key and velue
- Logo custom width not implementing
- Woocommerce textarea format ignored
- How best to check if a user is from China and hide content?
- Add another role to a user when they click a button?
- Using wordpress functions in class and change my code to OOP PHP
- Printing OEmbed URL based on Post selected w/o page refresh
- Unable to pass arguments to function used in add_action
- What is the proper way to call a function (from functions.php) on a link click?
- Multiple sections in Theme Customizer overwritten
- Using Tag Groups: Displaying groups and adjacent tags of current post
- How to create “page” used for generating PDF? [closed]
- Why isn’t my custom function kicking in from my functions.php file?
- Shortcoding with Divs
- Display a list of users with avatar filterable with alphabets
- Change default comments form title [duplicate]
- static array on functions.php
- Displaying categories
- Integrating CSS Into a WP Function Call [closed]
- Change background image based on tags
- Custom Navigation Bar JSON Syntax Error in JSON at Position 0
- How to extract URLs from wordpress taxonomies
- Warning: Illegal string offset ‘post’ and ‘page’
- How call WordPress shortcode inside function file
- strict custom php script on specific product category [closed]
- Add adjacent post function inside custom recent post function
- Customize Notification Email Sent to New User When Manually Created by Site Administrator
- I got this error POST https://localhost/meraboilerwp/[object%20Object] 404 (Not Found)
- How can I display a Divi content inside a modal based on an AJAX request