Skip to content

Load JS & CSS, When only shortcode called #3

@palpalani

Description

@palpalani

WordPress 3.6 has nice feature 'has_shortcode', using this we can load scripts when they called: https://codex.wordpress.org/Function_Reference/has_shortcode

Example:
function custom_shortcode_scripts() {
global $post;
if( has_shortcode( $post->post_content, 'videojs') ) {
wp_enqueue_script( 'custom-script');
}
}
add_action( 'wp_enqueue_scripts', 'custom_shortcode_scripts');

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions