I am trying to automate a whole bulk of my pages and one of the shortcodes I have created is to output the NextGen Gallery Tags by using the page custom fields that each page has a unique id. This id is actually tagged into certain galleries which I want to output on the page.

For those unfamiliar with NextGen Gallery tags shortcode. Please visit this link.

Each page has a custom field "gallery_id" which I input a unique tagged id everytime I create a page. I want every page to have the same template but pull different information depending on the custom fields.

This is my current shortcode, but at this stage, it is only outputting as text, but not as a shortcode. Does anyone know how to output this as a shortcode?

// Grab ID Custom Field [gallery_display] function lilap_gid( ){ $gid = get_post_meta(get_the_ID(), 'gallery_id', TRUE); return do_shortcode( '[ngg_images tag_ids="'. $gid .'"]'); } add_shortcode( 'gallery_display', 'lilap_gid' );

1 Answer 1


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);
echo do_shortcode( '[ngg_images tag_ids="'. $gid .'"]');
$content = ob_get_clean();
return $content;
add_shortcode( 'gallery_display', 'lilap_gid' );
  • Hello Benoti,I have tried this new code, it still outputs as text and not execute the shortcode. Was there something I needed to add after this to execute the shortcodes? Such as possibly an init function?
    – Lilap
    Nov 22, 2016 at 14:41
  • Verify that your shortcode is well formed imagely.com/docs/nextgen-gallery-shortcodes
    – Benoti
    Nov 22, 2016 at 15:18
  • In other term, i think that you want id for tag_ids but in the example they show slug.
    – Benoti
    Nov 22, 2016 at 15:23
  • Hello, Yes, I have verified the shortcode. I just copied and pasted the text output that my shortcode produces and it shows the gallery fine.
    – Lilap
    Nov 23, 2016 at 5:08
  • The slug shouldn't matter as it is text based tags that the gallery searches for. So I can add multiple tags with a comma and it will grab photos with those tags from different folders and show it all on one gallery.
    – Lilap
    Nov 23, 2016 at 5:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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