Support

Account

Home Forums General Issues Using get_field to create a shortcode

Helping

Using get_field to create a shortcode

  • Hi, I’m trying to use get_field to get the field value, and save it as a shortcode by creating a function first.

    function get_homepage_excerpt() {
    $myfield = get_field(‘homepage_excerpt’);
    return $myfield;
    }
    add_shortcode( ‘homepageexcerpt’, ‘get_homepage_excerpt’ );

    This seems simple, yet is not working. Am I missing something?

  • You have to supply the post ID of the home page if you are trying to do this on a different page

    
    $myfield = get_field('homepage_excerpt', $home_page_id);
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.