Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to generate short code for my gallery dynamically. For a single gallery, it is easy to create a short code for my gallery using

add_shortcode( 'image-gallery', 'gallery' )

Now my question is how can i create multiple short code for multiple gallery? Like for gallery 1 short code will be image-gallery-1, for 2 code will be image-gallery-2. I've tried this way

$all_gallery = $wpdb->prefix . 'gallery';
$all=$wpdb->get_results("select * from $all_gallery");
if(count($all)>0){
   foreach ($all as $a){
      add_shortcode( 'image-gallery-'.$a->id, 'gallery' );
   }
}

Its working nicely but when i deactivate the plugin and then activate the plugin again, a fatal error occurred and plugin is unable to activate.

share|improve this question
    
Where is this code? Please include the context. –  s_ha_dum Apr 21 '13 at 19:04
add comment

1 Answer

I cannot comment, I would if I could, but I can't, please don't down-vote

Could you not just use 1 shortcode with a parameter, e.g. instead of create one for each gallery image-gallery-1,image-gallery-2 etc, you could just use the ID as a parameter: image-gallery 1, image-gallery 2 ...

Then in your handling function you can simply test the parameter to see which gallery it is, I think this method is also slightly better for performance too as you don't need to call add_shortcode as many times, and all you are doing is removing one hyphen :)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.