Getting text from custom field from customizer

So I've created a panel in the customizer section in WordPress to add the phone number to the site. It works fine in the back end but it wont show up in the front end here is my functions.php function home_smart_register_theme_customizer( $wp_customize ) { $wp_customize->add_panel( 'contact_info', array( 'priority' => 10, 'theme_supports' => '', 'title' => __( 'Contact Info', 'home_smart' ), 'description' => __( 'Set your current address.', 'home_smart' ), ) ); $wp_customize->add_section( 'contact_details_block' , array( 'title' => __('Phone Number','home_smart'), 'panel' …
Category: Web

How to hide get_theme_mod if field empty

I'm using: get_theme_mod to show various pieces of info from the theme customizer, in the following format: <a href=" <?php get_theme_mod( $name, $default ) ?> ">This is the link</a> I would like to hide the whole line if that particular customizer field is empty. What could I wrap around the anchor to accomplish this?
Category: Web

Get_theme_mod not retrieving value

I'm using the Wordpress customizer feature to configure my theme and I constantly bumping into the same annoying issue, sometimes I don't get any value from get_theme_mod while I see the effect of my change in the preview window. Here is some code: $active_type="home"; $wp_customize->add_setting($active_type.'_categories_max',array( 'default' => '10', 'transport' => 'refresh' )); $wp_customize->add_control( $active_type.'_categories_max',array( 'type' => 'select', 'label' => 'Max Items', 'section' => $active_type.'_categories_section', 'choices' => array( '5' => '2', '10' => '10', '15' => '15', '20' => '20', ), …
Category: Web

After database migration, theme mods don't show

My Wordpress installation has only one theme which is active. The wp_option entry for it shows there are 31 theme mod entries. a:31:{s:18:"custom_css_post_id";i:5248;s:30:"theme_settings_api_keys_google";s:39:"xxx.....etc..";s:28:"theme_settings_xxx";........etc...etc...etc....;s:11:"custom_logo";i:5810;} however when I run get_theme_mod( 'my_mod_x' )) nothing comes is returned. So too when I run on the command line: wp theme mod get --all --allow-root. All I get is: +--------------------+-------+ | key | value | +--------------------+-------+ | custom_css_post_id | 5248 | +--------------------+-------+ Can anyone tell me what would cause WordPress to think there is only one …
Category: Web

retrieve "Link Color" value

I've set the Link color using the color picker in the front end. I want to use this color for buttons on the site so I used the following code in header.php <style> .btn{ background-color: <?php echo get_theme_mod( 'link_color' ); ?>; } </style> It worked and I could see the buttons change color to whatever I picked for Link Color setting. But it shows up only in Customization window. When I hit Publish and reload the site, I see the …
Category: Web

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

I need to create a menu - add links to it and then make it active - all from within my plugin at activation time. I have been able to create the menu and add links to it. But it does not become 'active' I can go in via the WP Interface and see the menu and then add it to the "footer" or make it the default "Top" menu but all of that requires user input. I want it …
Category: Web

get_option() vs get_theme_mod(): Why is one slower?

I've been using get_theme_mod() for some time in various projects of mine. I decided to take advantage of the Theme Customization API in WordPress v3.4 once it was available as I felt it was an indispensable tool for my clients to use. After some time, I began to notice that my sites were feeling a little more sluggish than usual, and the Customizer in particular took quite a long time to load. Through plenty of trial and error during my …
Category: Web

Issue with theme mod options during domain migration

I want to migrate my development wordpress site to the production domain. In order to success the migration I found and replace all previous url occurences (http://localhost) to the new (https://mywebsite.com). The problem is that old urls cannot be replaced directly in the field option_value of theme_mods_{your theme name} in the table wp_options because data in there are serialized. How can I replace old urls by the new without breaking theme settings ?
Category: Web

get_theme_mod only returns false

I have created a custom section with a setting with one control allowing users to choose fonts from a dropdown. However, when I use the get_theme_mod() function, and echo the results to a styles tag in the header, I get nothing. The debugger tells me that get_theme_mod() is returning 'false', when I expect it to return the value of the selected item. Using get_option() gives me the key of the option, "value3" and not the value. I would prefer to …
Category: Web

How to add "get_theme_mod" inside a shortcode?

I want to make dynamic the content inside a shortcode so I can modify it in the customizer. I created the customizer tabs. Now, I want to create a shortcode to place it anywhere in the page while being able to manipulate in the customizer. This is the code I'm working on. Thanks! <?php /* Plugin Name: .... */ // Exit if accessed directly if(!defined('ABSPATH')){ exit; } function customizer_inject_css() { ?> <style type="text/css"> :root { --theme-page-width: <?php echo get_theme_mod('theme_page_width', '1366px'); …
Category: Web

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

I'm adding some options to a theme through my plugin, I want to change this theme styles and I'm almost there... Now I need to know how I can hide the <style> tag when no settings are changed (all default not used), function myplugin_customize_css(){ ?> <style> h2 {color:<?php echo get_theme_mod('myplugin_h2_color'); ?>;} h3 {color:<?php echo get_theme_mod('myplugin_h3_color'); ?>;} p { color:<?php echo get_theme_mod('myplugin_p_color'); ?>; font-size:<?php echo get_theme_mod('myplugin_p_size'); ?>; } // more & more of these! </style> <?php } add_action( 'wp_head', 'myplugin_customize_css'); I …
Category: Web

Why is remove_setting and remove_control not working?

I've renamed my theme folder and all other title related bits, but I had a long list of settings and controls that were added with labels related to the old name, I want to remove these. I believe I'm doing it correctly with the following: function remove_settings_controls($wp_customize) { $wp_customize->remove_setting('psychic2016_logo'); $wp_customize->remove_control('psychic2016_logo'); $wp_customize->remove_setting('psychic2016_facebook'); $wp_customize->remove_control('psychic2016_facebook'); $wp_customize->remove_setting('psychic2016_twitter'); $wp_customize->remove_control('psychic2016_twitter'); $wp_customize->remove_setting('psychic2016_google_profile'); $wp_customize->remove_control('psychic2016_google_profile'); $wp_customize->remove_setting('psychic2016_google_analytics'); $wp_customize->remove_control('psychic2016_google_analytics'); $wp_customize->remove_setting('psychic2016_xml_id'); $wp_customize->remove_control('psychic2016_xml_id'); $wp_customize->remove_setting('psychic2016_xml_overflow'); $wp_customize->remove_control('psychic2016_xml_overflow'); $wp_customize->remove_setting('psychic2016_geoip_default'); $wp_customize->remove_control('psychic2016_geoip_default'); $wp_customize->remove_setting('psychic2016_geoip_status'); $wp_customize->remove_control('psychic2016_geoip_status'); $wp_customize->remove_setting('psychic2016_psychics_url'); $wp_customize->remove_control('psychic2016_psychics_url'); $wp_customize->remove_setting('psychic2016_offers'); $wp_customize->remove_control('psychic2016_offers'); $wp_customize->remove_setting('psychic2016_click2call'); $wp_customize->remove_control('psychic2016_click2call'); $wp_customize->remove_setting('psychic2016_prem'); $wp_customize->remove_control('psychic2016_prem'); $wp_customize->remove_setting('psychic2016_prem_badge'); $wp_customize->remove_control('psychic2016_prem_badge'); $wp_customize->remove_setting('psychic2016_sms'); $wp_customize->remove_control('psychic2016_sms'); $wp_customize->remove_setting('psychic2016_webchat_url'); $wp_customize->remove_control('psychic2016_webchat_url'); …
Category: Web

get_theme_mod doesn't return the theme customizer preview's new values in after_setup_theme hook

If I print the value of get_theme_mod( 'enable_sleek_header', false ) it is always the previously saved value. If I print the same thing in the header of the theme, it returns the value from customizer. Is it the expected behaviour? Am I using the wrong hook? Thanks <?php add_action( 'after_setup_theme', 'pagespeed_register_menus' ); function pagespeed_register_menus() { //Not getting the modified theme_mod from the customizer without saving. register_nav_menus( array( 'secondary' => __( 'Navigation above header', 'page-speed' ), ) ); if ( get_theme_mod( …
Category: Web

get_theme_mod not working

For some reason I cannot output the color. Everything works, but text_color just doesn't want to output its value. What is going wrong? Back end code (functions.php): $wp_customize->add_setting('text_color', array( 'default' => '#fff', 'sanitize_callback' => 'sanitize_hex_color', 'type' => 'option', )); $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'text_color', array( 'label' => __('Text color', 'pc'), 'section' => 'colors', 'settings' => 'text_color', ))); Front end code: if(!empty(get_theme_mod( 'text_color' ))) { ?> h1, h2, h3, h4, h5, h6 { color:<?php echo get_theme_mod( 'text_color' ); ?> } <?php }
Category: Web

Fetch customizer image and output as an inline css style background image

So I have a feeling this is quite simple, but Im a bone head since I'm still learning PHP as I hack away at themes via my own child-theming... In short, I've built a customizer section in my functions.php where I can add my own background image that I would then like to fetch in my search.php template and output as a inline background-image style. As far as I can tell, Im just not formatting my php correctly but I …
Category: Web

get_theme_mod is returning a number rather than my image file

This is my first time attempting at implementing a custom panel into the customizer so bare with me please... In short, I am child-theming my site and want to make a basic modification to the parent theme for my blog posts. The way it works now is when you hover over a blog post, there is a font awesome icon which shows up in the middle of the overlay... what I plan to do is replace the font awesome icon …
Category: Web

if has theme mod

Does someone know how to write the next line in wordpress PHP, because i'm not that great with PHP. If_theme_mode has content echo { my content } else { other content }; thnx
Category: Web

Return a numerical function value in Customizer controls

I'm trying to add some controls to the WordPress Customizer feature, but I'm having trouble pulling the numerical value from the control to use in the theme. The section appears in the Customizer tab, and I can change the input, but the controls have no effect on the theme. I've looked up tutorials that use the get_theme_mod and inline styles to set attributes for divs, but I haven't been able to figure out exactly how to make the control id …
Category: Web

How to make get_theme_mod work with AJAX in the customizer preview

Is it possible to make the get_theme_mod work after refresh in the customizer preview pane when it's being called inside a template part by AJAX? I have a theme that loads the posts on scroll (infinite scroll) and everything works except it doesn't output the updated theme mods in the customizer preview. It only outputs the new theme mods when I hit the save button. Any idea how to make it update after a refresh as well? My control settings: …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.