I have this function in my functions.php file to create opengraph code dynamically for each post:
/ Set your Open Graph Meta Tags
function fbogmeta_header() {
if (is_single()) {
//getting the right post content
$postsubtitrare = get_post_meta($post->ID, 'id-subtitrare', true);
$post_subtitrare = get_post($postsubtitrare);
$content = limit(strip_tags($post_subtitrare-> post_content),297);
?>
<meta property="og:title" content="Sermon Note: <?php the_title(); ?>"/>
<meta property="og:description" content="<?php echo $content; ?>" />
<?php
}
}
add_action('wp_head', 'fbogmeta_header');
But how do I get <meta property="og:description" content="<?php echo $content; ?>" /> to show my custom field "wpcf-notes-description" instead of "$content"? I can't seem to come up with the right code. Basically I want it to show the notes description of the current post in the og:description.
So if I put this in the single page template, it shows the data inside the actual page: <?php $notes_desc = get_post_meta($post->ID, 'wpcf-notes-description', true);?> So technically the code works.
But if I put it in this function code into the functions.php file instead, so that I can use the data in the og tags, the content og tag ends up being empty still. Am I missing something?
function fbogmeta_header() {
{
//getting the right post content
$postsubtitrare = get_post_meta($post->ID, 'id-subtitrare', true);
$post_subtitrare = get_post($postsubtitrare);
$content = limit(strip_tags($post_subtitrare-> post_content),297);
$notes_desc = get_post_meta($post->ID, 'wpcf-notes-description', true);
?>
<meta property="og:description" content="<?php echo $notes_desc; ?>" />
<?php
}
}
add_action('wp_head', 'fbogmeta_header');