Using Custom Fields:
You can use custom fields for each page, if you need something more specific (maybe a product where you need an specific image for each page), taking the og values for example:
1.- Go to the edit page and check the custom fields checkbox so it can be seen below the editor
2.- Enter a new custom field
it should look like this, the name
is your $key
3.- Save or Update the page.
4.- Add this code to your functions.php
function opengraph_tags() {
/* we set the URL */
$og_url = get_permalink();
/* we set the site name */
$og_site_name = get_bloginfo();
/* we set the image */
/* we check for a featured image */
global $post;
$og_img_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'medium');
$key = 'description';
/* MY CUSTOM VALUE I WANT TO PUT FROM THE CONTENT TO THE HEADER */
$og_description = get_post_meta($post->ID, $key , true);
?>
<meta property="og:description" content="<?php echo $og_description; ?>"/>
<meta property="og:type" content="website" />
<meta property="og:url" content="<?php echo $og_url ?>"/>
<meta property="og:site_name" content="<?php echo $og_site_name ?>"/>
<meta property="og:image" content="<?php echo $og_img_src[0]; ?>"/>
<?php
}
add_action('wp_head', 'opengraph_tags', 5);
you can see i am grabbing the custom field with $key
which can be anything you want, and also you can grab all the custom values you want, provided that you created them, you can set default values there too with a simple if(empty($myValue))
, if you inspect the header you will see something like this:
Now if you want to use other values in header.php or even footer.php just set the custom field and use this code to grab the value:
<?php
global $post;
$key = 'description';
/* MY CUSTOM VALUE I WANT TO PUT FROM THE CONTENT TO THE HEADER */
$og_description = get_post_meta($post->ID, $key , true);
?>