Skip to content

Instantly share code, notes, and snippets.

@WPDevHQ
Last active March 23, 2016 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WPDevHQ/9bf951220c1ac47e6f6e to your computer and use it in GitHub Desktop.
Save WPDevHQ/9bf951220c1ac47e6f6e to your computer and use it in GitHub Desktop.
How to add inline styles the right way
<?php
/*
* As a wise theme reviewer advised - theme options are required to be within the Customizer!
*/
function themename_custom_css_adjust() {
$css = '';
$bg_color = get_theme_mod( 'themename_menu_bg_color' );
$link_color = get_theme_mod( 'themename_last_link_color' );
$link_hover = get_theme_mod( 'themename_last_link_hover' );
$css .= '
.main-navigation li:last-child {background-color: ' . $bg_color . ';}
.main-navigation li:last-child a {color: ' . $link_color . ';}
.main-navigation li:last-child a:hover {color: ' . $link_hover . ';}
';
}
wp_add_inline_style( 'themename-style', $css ); // Assuming that `theme-style` is the handle for your main stylesheet enqueue.
}
add_action( 'wp_enqueue_scripts', 'themename_custom_css_adjust' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment