Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

wordpress enqueue if shortcode

//Enqueue only if shortcode Exists on wp_content
add_action('wp_enqueue_scripts', 'myplugin_stylesheet');
function myplugin_stylesheet() {
  global $post;
  if( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'myplugin-shortcode-name') ) {
    wp_enqueue_style( 'myplugin-style', plugins_url('myplugin-style.css', __FILE__));   
  }
}
Source by wordpress.stackexchange.com #
 
PREVIOUS NEXT
Tagged: #wordpress #enqueue #shortcode
ADD COMMENT
Topic
Name
7+1 =