Skip to content

Instantly share code, notes, and snippets.

@scottnix
Created October 5, 2012 16:49
Show Gist options
  • Save scottnix/3840934 to your computer and use it in GitHub Desktop.
Save scottnix/3840934 to your computer and use it in GitHub Desktop.
Example of adding a shortcode using custom fields "custom-gallery"
function snix_childtheme_gallery() {
global $post;
// display this only on pages
if (is_page()) {
// get the correct custom field data
$custom_gallery = get_post_meta($post->ID, 'custom-gallery', true);
// if custom field is available, do this
if ($custom_gallery) {
// do_shortcode is needed
$galleryoutput = do_shortcode( $custom_gallery ) ;
// put it on the screen
print $galleryoutput;
// if no custom field, do nothing
} else {
// silence
}
}
}
// then we will hook this on "thematic_abovecontainer", but the hook can be moved anywhere.
add_action('thematic_abovecontainer', 'snix_childtheme_gallery');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment