Skip to content

Instantly share code, notes, and snippets.

@mathetos
Last active October 27, 2016 04:10
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 mathetos/c665f24cd7d8d8a1fbad63a8d5c9a741 to your computer and use it in GitHub Desktop.
Save mathetos/c665f24cd7d8d8a1fbad63a8d5c9a741 to your computer and use it in GitHub Desktop.
Sample Shortcode with Selectively Enqueued Stylesheet
<?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