WordPress.org

Ready to get started?Download WordPress

Forums

Add Custom Field within Shortcode using do_shortcode (6 posts)

  1. ciaranm
    Member
    Posted 3 years ago #

    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.

  2. alchymyth
    Forum Moderator
    Posted 3 years ago #

    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"]'); ?>`

  3. ciaranm
    Member
    Posted 3 years ago #

    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!

  4. easilyamused
    Member
    Posted 2 years ago #

    @ciaranm Thanks Work like a charm ;c )

  5. AardvarkGirl
    Member
    Posted 2 years ago #

    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)

  6. AardvarkGirl
    Member
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.