Skip to content

Instantly share code, notes, and snippets.

@mehul0810
Created November 2, 2018 14:54
Show Gist options
  • Save mehul0810/ac859933b4aaab74bf94e8a31140a928 to your computer and use it in GitHub Desktop.
Save mehul0810/ac859933b4aaab74bf94e8a31140a928 to your computer and use it in GitHub Desktop.
<?php
/**
* Enqueue Inline Styles in WordPress.
*
* @author Mehul Gohil
* @link https://www.mehulgohil.in/code-snippets/enqueue-inline-styles/
*/
function mg_enqueue_inline_styles() {
$css = '';
$logo = get_option( 'options_mg_site_logo' );
if ( $logo ) {
$logo = wp_get_attachment_image_src( $logo, 'full' );
$css .= '
.site-title { background-image: url(' . $logo[0] . ');}
';
}
// If $css is not empty, then add inline style.
if ( ! empty( $css ) ) {
wp_add_inline_style( 'mg-custom-theme-style-handle', $css );
}
}
add_action( 'wp_enqueue_scripts', 'mg_enqueue_inline_styles' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment