• Resolved danielcalifornia

    (@danielcalifornia)


    Hi!

    How can I echo the meta-description from The SEO Framework?

    <?php echo get_???(); ?>

    Some people it’s “get_post_meta”, but that didn’t work for me…

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Sybre Waaijer

    (@cybr)

    Hello!

    We have a “god”-function to retrieve data from The SEO Framework’s main “god”-object. That function is the_seo_framework(). When TSF isn’t active, or when you call a non-existing method, the function will prevent your site from crashing. So, only a function_exists() call is necessary. This way, you need not worry about plugin updates breaking your website. You’ll see how it works below.

    You can use the method below to get the current description. It automatically considers generating a description for you, as well:

    $meta_description = function_exists( 'the_seo_framework' ) ? the_seo_framework()->get_description() : '';
    
    echo esc_html( $meta_description );
    

    If you want to get it from a different page then you can feed the method with a query argument:

    // Page query
    $query = [
       'id' => 42,
    ];
    
    $meta_description = function_exists( 'the_seo_framework' ) ? the_seo_framework()->get_description( $query ) : '';
    
    echo esc_html( $meta_description );
    

    When you supply the taxonomy, you’ll automatically retrieve the description for only a term. For example:

    // Term query
    $query = [
       'id'       => 42,
       'taxonomy' => 'category'
    ];
    
    $meta_description = function_exists( 'the_seo_framework' ) ? the_seo_framework()->get_description( $query ) : '';
    
    echo esc_html( $meta_description );

    I hope this helps 🙂 Cheers!

    • This reply was modified 4 years, 3 months ago by Sybre Waaijer. Reason: clarity
    Thread Starter danielcalifornia

    (@danielcalifornia)

    Hi Sybre,
    thank you very much!
    Worked! 🙂

    Hey Daniel, sorry to bother you further, but please consider writing a short review of TSF. It does help and makes the whole team happy. Thank you.

    https://wordpress.org/support/plugin/autodescription/reviews/#new-post

    In any case, have a nice day!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Echo (PHP) meta description from The SEO Framework’ is closed to new replies.