Multiple Instances Breaks Shortcode
-
I had initially wrote a shortcode that displayed author profiles based on id. For example
[user-profile id="1"]
would display the profile block for author 1. It worked. I was able to use it multiple times within a page.function user_profile( $atts, $content = null ) { extract(shortcode_atts(array('id' => ''), $atts)); include ('user-profile.php'); }
…but since the shortcode output was showing up before other entry content regardless of its place in the code (same issue here) I added the fix described here:
function user_profile( $atts, $content = null ) { extract(shortcode_atts(array('id' => ''), $atts)); function get_user_profile() {include ('user-profile.php');} ob_start(); get_user_profile(); $output_string=ob_get_contents(); ob_end_clean(); return $output_string; }
…which worked to solve the positioning problem but broke multiple instances of the shortcode.
[user-profile id="1"]
works but[user-profile id="1"] [user-profile id="2"]
breaks it—the page just stops loading at that point.The html/php in
user-profile.php
is viewable here.How can I modify the shortcode function to allow multiple instances?
- The topic ‘Multiple Instances Breaks Shortcode’ is closed to new replies.