Split Content and Gallery

Open to anybody who can simplify this but here’s what I came up with that worked for me. First thing’s first – get the gallery, using get_post_gallery(), as soon as the loop starts: <?php if( have_posts() ) : ?> <?php while( have_posts() ) : the_post(); $gallery = get_post_gallery(); $content = strip_shortcode_gallery( get_the_content() ); ?> <div … Read more

apply_filters(‘the_content’, $content) vs do_shortcode($content)

QUESTION AND ANSWER REVISITED There are sometimes these questions that nags you and hunts you down later in life again, and this is one such question. This question had me thinking about an alternative solution to the problem. As I already stated, custom fields and meta boxes are there to store small pieces of meta … Read more

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 ‘–&gt; Contact &nbsp;|&nbsp; Terms … Read more