Created
June 17, 2016 22:20
-
-
Save Page-Carbajal/a033555b2a73fd8507714651c0909519 to your computer and use it in GitHub Desktop.
WordPress - How to dynamically load scripts and styles based on post content
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 | |
add_action('template_redirect','justIfContentHas'); | |
function justIfContentHas() | |
{ | |
global $post; | |
// Set the condition for loading your resources | |
if( has_shortcode($post->post_content, 'my_short_code') ){ | |
$pathToFile = dir(__FILE__); | |
wp_enqueue_scripts('handler', $pathToFile, array('jquery','or','your','dependencies') ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment