• I am using do_shortcode to include a Flickr Gallery shortcode in my theme.

    I would like to add a custom field within the shortcode so that I can just add the tag name in the custom field and it would be populated in the shortcode.

    Here is my current code:
    <?php echo do_shortcode( '[slickr-flickr type="slideshow" tag="Tag Name" size="small"]'); ?>

    And I would like to replace “Tag Name” in the shortcode with the following custom field:

    <?php getCustomField('tag-name'); ?>

    Is there a way to do this?

    Thanks in advance.

Viewing 5 replies - 1 through 5 (of 5 total)
  • the following depends on if the function getCustomField() returns or echoes the value of the custom field; it is based on the assumption/hope that the function will return the value – you could try:

    <?php $value = getCustomField('tag-name'); ?>

    <?php echo do_shortcode( ‘[slickr-flickr type=”slideshow” tag=”‘ . $value . ‘” size=”small”]’); ?>`

    Thread Starter ciaranm

    (@ciaranm)

    Thanks very much alchymyth…. You led me down the right track and I have now figured it out…

    For anyone looking to do something similar, this is my code:

    <?php $var = get_post_meta($post->ID, 'gallery-code', true);
    if ($var == '')
    { }
    else { echo do_shortcode( '[slickr-flickr type="slideshow" tag="' . $var . '" size="small"]'); } ?>

    It checks to see if the custom field has a value and if so returns the custom field as the variable in the shortcode. If no custom field is entered is shows nothing… Works a treat!

    easilyamused

    (@easilyamused)

    @ciaranm Thanks Work like a charm ;c )

    AardvarkGirl

    (@aardvarkgirl)

    Ok, I did this with PWA+php / Picasa album. I posted here first because it wasn’t work (I had a type error in my code). I hope this helps someone else out too. ??

    I’ve got the PWA+php plugin to pull in Picasa albums (which works via short code fine on the site). I wanted to pull images into a div within the footer div.

    I want to pull the ‘pony’ album in on the ‘pony’ page by using the short code:

    [pwaplusphp album="pony"]

    Here is the code I’m using;

    <div id="photogallery">
    <?php $var = get_post_meta($post->ID, 'gallery-code', true);
    if ($var == '')
    { }
    else { echo do_shortcode( '[pwaplusphp album="' . $var . '"]'); } ?>
    </div><!--photogallery-->

    The custom field name: gallery-code
    The custom field value: ‘pony’ (the album name from Picasa)

    AardvarkGirl

    (@aardvarkgirl)

    Ok, but I did find a glitch. The lightbox plugin doesn’t work when the images are in the footer. :-\

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Add Custom Field within Shortcode using do_shortcode’ is closed to new replies.