Meta Description From Custom Field

Community Forums Forums General Discussion Meta Description From Custom Field

This topic is: not resolved

This topic contains 5 replies, has 2 voices, and was last updated by  rfmeier 1 year ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #47750

    Vikram
    Participant
    Post count: 7

    Hi there,

    I am using Eleven40 theme.

    I would like to for my site’s meta tag (and not the post meta), display the summary from a custom field value.

    So, this should look like this:

    <meta name="description">Summary from Custom Field</meta>

    I know how to get the value from the custom field in my functions.php.

    BUt I can’t seem to figure out how to add that value to the meta tag.

    Any help appreciated!

    #47917

    rfmeier
    Participant
    Post count: 596

    Hello,

    You can start by checking out the source code for the ‘genesis_meta’ action in the genesis/lib/structure/header.php file. You can either remove the default action and add your own or use the ‘_genesis_description’ custom meta field.

    I hope this points you in the right direction.


    #48118

    Vikram
    Participant
    Post count: 7

    Thank you Ryan for pointing me in the right direction.

    This is the solution that I came up with:

    In the functions.php, I added a custom function:

    add_action('genesis_meta', 'custom_seo_description');
    function custom_seo_description() {
      if(is_singular('post')) {
        echo '<meta name="description" content="' . get_field('project_summary') . '" />';
      } else if(is_archive()) {
        echo '<meta name="description" content="' . category_description() . '" />';
      } else if(is_singular('competition')) {
        echo '<meta name="description" content="' . get_the_title() . '" />';
      }
    }
    #48128

    rfmeier
    Participant
    Post count: 596

    Did that work okay for you?


    #48129

    Vikram
    Participant
    Post count: 7

    Yes that solution works for me. Is there an issue with this solution that I can’t see?

    Vikram

    #48131

    rfmeier
    Participant
    Post count: 596

    None that I can see. I am glad it worked. Good luck.


Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.