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
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
if (get_field('gtin', $post_id)) {
?><meta property="GTIN" content="<?php the_field('gtin', $post_id); ?>" /><?php
}
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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.