Conditionally Loading JavaScript/CSS for Shortcodes

Based on my own experience, I’ve used a combination of method 1 & 2 – the architecture and footer scripts of 1, and the ‘look-ahead’ technique of 2. For the look-ahead though, I use regex in place of stripos; personal preference, faster, and can check for ‘malformed’ shortcode; preg_match( ‘#\[ *shortcode([^\]])*\]#i’, $content ); If you’re … Read more

Enqueue Scripts / Styles when shortcode is present

I found an other way that works well for me: When initializing the plugin, do not enqueue your scripts and styles, but register them with wp_register_style and wp_register_script. Next you can load the script/style on demand. For example when you render a shortcode with wp_enqueue_style(“your_style”) and wp_enqueue_script(“your_script”). Here is an example plugin using this method … Read more

convert it into short code & explan how? [closed]

A function can be created that generates the output, then that function can be tied to a shortcode using the Shortcode API: /** * Returns –> Contact | Terms of Service | Privacy Policy | Careers * * @parm array $atts * @return string */ function wpse241695_arrow_contact_terms_of_service_privacy_policy_careers( $atts ) { return ‘–> Contact  |  Terms … Read more