• Resolved technabob

    (@technabob)


    I was wondering if there’s any way to designate that a post is primarily an og:type of “video” instead of article, and to pass it the video URL and video metadata? I’ve run into at least one use case where a social media site wants to be able to identify video posts differently from articles, and is expecting the og:type to be video. For example, this post…

    https://theawesomer.com/quadcopter-racing-pov/310714/

    In the IDEAL world, I’d be able to just use the category “videos” to designate that a post is not an article but a video, but what makes things tricky for us is that the video URL isn’t in the post content but a custom field, so I’m not sure how to handle that.

    I suppose I could just code my own implementation specifically for video posts directly in my header.php, but then I need to disable the og:type=”article” for these specific pages.

    Any ideas?

    https://www.ads-software.com/plugins/add-meta-tags/

Viewing 15 replies - 1 through 15 (of 24 total)
  • Plugin Author George Notaras

    (@gnotaras)

    Hello technabob,

    Being able to control og:type sounds like a nice idea and would definitely be useful for video posts.

    My thoughts are that it should be possible to change og:type via:

    1) a filter function programmatically
    2) by taking into account the post format as it happens with Twitter Cards.

    What I would like to know, according to your research, is whether other changes in the opengraph metadata would be needed if the og:type was set to video. From what I read, the rest of the opengraph meta tags could be exactly the same as those of the og:type=article. Is this correct? Do I miss anything?

    but what makes things tricky for us is that the video URL isn’t in the post content but a custom field, so I’m not sure how to handle that.

    I see. So, the plugin does not recognize the embedded video and never outputs any video related meta tags, right?

    I have a solution in mind for this as well. I’ll do some tests at some later time today and post back.

    My suggestion would be to avoid a custom solution within header.php. I’ll post some sample code that makes use of the plugin filter hooks so as to change the metadata and also be able to inject the video urls from the custom fields to the algorithm that processes embedded media.

    Feel free to post any extra details that you think would be useful.

    Kind Regards,

    George

    Thread Starter technabob

    (@technabob)

    George: I think you’re right – the main thing that needs to be different is that the og:type is set to video. In terms of extracting the video URL, I think it should be added as another og:video and NOT as the og:url, since we want the og:url to remain our page’s URL and not the URL of the video clip.

    Make sense?

    Plugin Author George Notaras

    (@gnotaras)

    Yes, og:url needs to be the page’s url. A new set of og:video meta tags will be generated for each embedded video. I’ll post sample code about how to use the video from a custom field for this.

    Checking the metadata of the page you posted earlier, I see this metadata:

    <meta property="og:video" content="https://player.vimeo.com/video/" />
    <meta property="og:video:type" content="application/x-shockwave-flash" />
    <meta property="og:video:width" content="640" />
    <meta property="og:video:height" content="480" />

    May I ask if this has been generated by the plugin or it is the result of custom code? This is because the og:video url lacks the video ID. If this output is generated by the plugin, then there might be a bug somewhere.

    Thanks in advance,

    George

    Thread Starter technabob

    (@technabob)

    That’s being generated by the plugin, so I’m not sure where that came from. I know in the case where we’ve got multiple videos on a page – those are injected into the the_content , and the plugin seems to account for those correctly.

    For example:
    https://theawesomer.com/powering-a-lantern-festival/310625/

    The large “hero” video is coming from a custom field, but the second one is in the content, so you’ve identified that one properly.

    Plugin Author George Notaras

    (@gnotaras)

    Hi technabob, I’m sorry for my late reply. I was away. I’ll release a new version shortly that makes it possible to resolve all the above issues. I had to do some research about the opengraph protocol regarding object types.

    George

    Plugin Author George Notaras

    (@gnotaras)

    Regarding og:type: it is auto-set to video.other if post format is set to video or if it is the page of a video attachment. Can be also set programmatically via a filter.

    Regarding the injection of video links which are embedded outside the scope of the WP oembed mechanism you can attach a filtering function to the amt_embedded_media_external hook and supply the media URLs, for example the URL from your custom field. Sample code:

    function amt_add_pseudo_embedded_media( $links, $post ) {
        $custom_video_url = get_post_meta($post->ID, '_FIELD_NAME', true);
        if ( ! empty( $custom_video_url ) ) {
            $links[] = $custom_video_url;
        }
        return $links;
    }
    add_filter( 'amt_embedded_media_external', 'amt_add_pseudo_embedded_media', 10, 2 );

    This code can be added in the functions.php file of the theme or in a custom plugin.

    Of cource it will work only for embeddable media that can be detected by the algorithm (youtube, vimeo, vine, soundcloud, flickr).

    Please let me know if everything works as expected.

    George

    Thread Starter technabob

    (@technabob)

    Thanks, George. I’ll play around with this over the weekend. Really appreciate your help.

    Plugin Author George Notaras

    (@gnotaras)

    OK, feel free to post any questions.

    Thread Starter technabob

    (@technabob)

    So far, I can’t seem to get it to output anything. I’m currently sticking the video embed code in a custom field called “video” but I usually have the link in a field called “link”. I tried both of these data sources, and neither resulted in any og:video metadata being output.

    Here’ are some examples you can use if you want to check on your end:

    video custom field: <iframe width="960" height="540" src="https://www.youtube.com/embed/u76DYViVQto" frameborder="0" allowfullscreen></iframe>

    link custom field: https://www.youtube.com/watch?v=u76DYViVQto

    Any thoughts?

    Plugin Author George Notaras

    (@gnotaras)

    Hi,

    function amt_add_pseudo_embedded_media( $links, $post ) {
        $custom_video_url = get_post_meta($post->ID, 'link', true);
        if ( ! empty( $custom_video_url ) ) {
            $links[] = $custom_video_url;
        }
        return $links;
    }
    add_filter( 'amt_embedded_media_external', 'amt_add_pseudo_embedded_media', 10, 2 );

    If the link field contains the URL: https://www.youtube.com/watch?v=u76DYViVQto, then the Opengraph metadata should contain a set of og:video:.. tags for it. Isn’t it the case?

    Plugin Author George Notaras

    (@gnotaras)

    I just tested the above code and it works.

    Thread Starter technabob

    (@technabob)

    Odd. I tried removing everything else in my functions.php to ensure there was no conflict with other filters and I’m still getting no og:video tag.

    I wonder if there’s something I’ve got configured differently in my Add-Meta-Tags plugin settings. Otherwise, I’m assuming its some other plugin conflict.

    Thread Starter technabob

    (@technabob)

    Oops. My bad. I didn’t realize you released a plug-in update. I was still running 2.6.8. It’s working now. Thanks!

    Plugin Author George Notaras

    (@gnotaras)

    OK. Thanks for letting me know.

    Also the description issue from the other topic should be resolved as well. Can you confirm?

    Thread Starter technabob

    (@technabob)

    Yes. That’s resolved. I did notice one other – somewhat related issue with the og:video tags that are injected from the_content. If you have a link to Vimeo that ISN’T a video embed – i.e. to the video author’s page like: https://vimeo.com/stevenbenedict, we’re getting an extra og:video tag that just links to : https://player.vimeo.com/video/

    I’m assuming this is a bug in the WP oembed mechanism, but I figured I’d mention it in case it’s something specific to your plugin.

Viewing 15 replies - 1 through 15 (of 24 total)
  • The topic ‘Open Graph tags for videos?’ is closed to new replies.