Custom shortcode with do_shortcode and substr

using php substr requires you add a start point when calling substr function http://php.net/manual/en/function.substr.php A possible fix: function my_shortcode_function() { $string = “”; $string = do_shortcode(‘[different_shortcode]’); $string = substr($string, 0, 4); return $string; } add_shortcode( ‘my_shortcode’, ‘my_shortcode_function’ );

Shortcode or Template Page

Actually it depends. If you’re adding the functionality through a custom plugin or any third party solution rather than theme then the shortcode is best, otherwise you can use a template. You also can use template file with plugin, but then the theme and the plugin will be tightly coupled. That’s kinda not preferred. But … Read more

PHP and Shortcode Combination

Concatenate the shortcode with the field value just before you evaluate it with do_shortcode. the_field(‘link’) will automatically output the value while get_field(‘link’) will return the value. <?php echo do_shortcode(‘[sociallocker]’. get_field(‘link’) . ‘[/sociallocker]’);?> The problem you had before is that your evaluating the first 1/3 which doesn’t include the data. Then you print the data. And … Read more

Output Custom Field value to shortcode

Depending on the ngg_images shortcode, you maybe need to echo the do_shortcode function. You can try function lilap_gid($atts, $content = “”){ $gid = get_post_meta(get_the_ID(), ‘gallery_id’, TRUE); ob_start(); echo do_shortcode( ‘[ngg_images tag_ids=”‘. $gid .'”]’); $content = ob_get_clean(); return $content; } add_shortcode( ‘gallery_display’, ‘lilap_gid’ );

How to insert current user ID in a shortcode?

You didn’t say how you were going to implement the code: If you are using page templates or custom post pages, you could do this: <?php $user_id = get_current_user_id(); if ($user_id == 0) { echo ‘You are currently not logged in.’; } else { echo do_shortcode(‘[pods-form name=”user” id=”‘.$user_id.'” fields=”my_field, my_field_2, my_field_3″]’); } ?> are you … Read more