Last active
October 27, 2016 04:10
-
-
Save mathetos/c665f24cd7d8d8a1fbad63a8d5c9a741 to your computer and use it in GitHub Desktop.
Sample Shortcode with Selectively Enqueued Stylesheet
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 | |
/* | |
* Example Shortcode and Globally Enqueued Stylesheet | |
* | |
*/ | |
// Our Shortcode function | |
function hiroy_shortcode( $content = null ) { | |
// Enqueue the stylesheet now | |
wp_enqueue_style( 'hiroy-css' ); | |
$content = '<h2>Hi Roy!</h2>'; | |
return $content; | |
} | |
// Our Shortcode Action | |
add_shortcode( 'hiroy', 'hiroy_shortcode' ); | |
// Register the Stylesheet so it's ready to go. | |
function hiroy_enqueue_scripts() { | |
wp_register_style( 'hiroy-css', 'hiroy.css', 'parent-stylesheet', '1.0', all ); | |
} | |
// Enqueue Stylesheet Action | |
add_action( 'wp_enqueue_scripts', 'hiroy_enqueue_scripts' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment