Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Does anyone have any Idea how to populate the attached audio file URL into meta elements? Just as you would featured image or something Here's what I tried:

<meta property="og:audio" content="<?php $meta_values = get_post_custom($post->ID);
if(isset($meta_values['meta_audio_attachment'][0])){ $url =$meta_values['meta_audio_attachment'][0]; } ?>" />
<meta property="og:audio:title" content="Test" />
<meta property="og:audio:artist" content="Test" />
<meta property="og:audio:album" content="Test Album" />
<meta property="og:audio:type" content="application/mp3" />

Facebook populates all the rest of the meta's except the audio url?

share|improve this question

2 Answers 2

You are probably using this code in your theme's header.php. When this file is loaded $post is not available yet (it'll be inside the Loop). So you'd need to declare before anything global $post;.

But that's not the best approach. If you swap themes, what? Do it again?
See: Where to put my code: plugin or functions.php?

With the following plugin, we will hook into wp_head and print our meta based on some Conditional Tags:

<?php
/* Plugin Name: Print Audio OG */

add_action( 'wp_head', 'print_audio_og_wpse_99152', 0 );

function print_audio_og_wpse_99152()
{
    // Print only in single posts or pages
    if( is_single() || is_page() )
    {
        global $post;
        $meta_value = get_post_meta( $post->ID, 'meta_audio_attachment', true );
        if( $meta_value )
            echo "
<meta property='og:audio' content='$meta_value' />
<meta property='og:audio:title' content='$post->post_title' />
<meta property='og:audio:artist' content='Test' />
<meta property='og:audio:album' content='Test Album' />
<meta property='og:audio:type' content='application/mp3' />
";
    }
}

You'll have to adapt get_post_meta.
Increase the hook priority, now 0 (zero), to move the insertion point in the rendered HTML.

share|improve this answer
    
Hmm so just put this into say "audioog" folder inside plugins and create index.php and put the code in? Or just add it to functions? Also why do I have to adapt if its already actioning into wphead? –  shawn merrihew May 12 '13 at 4:57
    
Yes, a simple plugin is very simple. No, don't add to functions, this is not a case for it. Adapt because you're using get_post_custom, grab the meta data as you wish/need. –  brasofilo May 12 '13 at 5:02
    
I'm sorry if I'm asking something simple,but I'm very confused. I thought "meta_audio_attachment“ was already done with global post? global $post; $meta_value = get_post_meta( $post->ID, 'meta_audio_attachment', true ); –  shawn merrihew May 12 '13 at 5:30
    
Show your full code. –  brasofilo May 12 '13 at 12:56

You should be a whitelisted partner to embed a audio file. Read https://developers.facebook.com/docs/opengraph/music/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.