Support

Account

Home Forums General Issues Trying to Add ACF Custom Field to Page Source Meta at the top For SEO Reply To: Trying to Add ACF Custom Field to Page Source Meta at the top For SEO

  • Hi John,

    Thanks so much for your time on this. I replaced the “// your code to output meta tags here” with the code above, and the following code was my block of text added to the functions.php of my child theme:

    add_action('wp_head', 'product_details_meta');
    function product_details_meta() {
      // get the queried object
      $queried_object = get_queried_object();
      // see if it's a post
      if (!is_a($queried_object, 'WP_POst')) {
        // not a post
        return;
      }
      // set $post_id
      $post_id = $queried_object->ID;
      // check post type
      if (get_post_type($post_id) != 'product') {
        // not a product
        return;
      }
      // use $post_id to get ACF field values
      $value = get_field('gtin', $post_id);
      if (get_field('gtin', $post_id)) {
      ?>
      <meta property="GTIN" content="<?php the_field(gtin', $post_id);?>" />
      <?php 
    }
    

    Sadly, it threw up a critical error on all pages of my site when I included this.

    If you happen to see anything glaring that I mistakenly did with the code above, please let me know. Once again, thanks for your time and your help is greatly appreciated. Thanks again.