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)

The topic ‘Using get_field to create a shortcode’ is closed to new replies.