Created
November 2, 2018 14:54
-
-
Save mehul0810/ac859933b4aaab74bf94e8a31140a928 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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