Home / Admin / AIOSEO Movie Poster Integration – TMDb & ACF Compatibility Fix [for the fmovie theme by fr0zen]
Duplicate Snippet

Embed Snippet on Your Site

AIOSEO Movie Poster Integration – TMDb & ACF Compatibility Fix [for the fmovie theme by fr0zen]

This snippet overrides AIOSEO's default image with the TMDb movie poster stored in the ACF 'poster_path' field. Built as a compatibility fix for the fmovie theme by fr0zen.

<10
Code Preview
php
<?php
/**
 * AIOSEO Movie Poster Integration – TMDb & ACF Compatibility Fix
 *
 * This snippet overrides AIOSEO's default image with the TMDb movie poster
 * stored in the ACF 'poster_path' field. Built as a compatibility fix for
 * the fmovie theme by fr0zen.
 *
 * Applies to:
 * 1. Movie schema image (for Google rich results)
 * 2. Open Graph og:image (for Facebook, WhatsApp, Messenger, etc.)
 * 3. Twitter twitter:image (for X/Twitter cards)
 *
 * Requirements:
 * - Advanced Custom Fields (ACF)
 * - All in One SEO (AIOSEO)
 * - fmovie theme by fr0zen
 */
// 1. Fix Movie Schema Image
add_filter( 'aioseo_schema_output', 'aioseo_fix_movie_poster_schema' );
function aioseo_fix_movie_poster_schema( $graphs ) {
    if ( is_singular( 'post' ) ) {
        $poster_path = get_field( 'poster_path', get_the_ID() );
        if ( ! empty( $poster_path ) ) {
            $poster_url = 'https://image.tmdb.org/t/p/w600_and_h900_bestv2' . $poster_path;
            foreach ( $graphs as $index => $graph ) {
                if ( ! empty( $graph['@type'] ) && 'Movie' === $graph['@type'] ) {
                    $graphs[ $index ]['image'] = $poster_url;
                    break;
                }
            }
        }
    }
    return $graphs;
}
// 2. Fix Facebook / Open Graph Image
add_filter( 'aioseo_facebook_tags', 'aioseo_fix_movie_poster_og' );
function aioseo_fix_movie_poster_og( $facebookMeta ) {
    if ( is_singular( 'post' ) ) {
        $poster_path = get_field( 'poster_path', get_the_ID() );
        if ( ! empty( $poster_path ) ) {
            $poster_url = 'https://image.tmdb.org/t/p/w600_and_h900_bestv2' . $poster_path;
            $facebookMeta['og:image']            = $poster_url;
            $facebookMeta['og:image:secure_url'] = $poster_url;
        }
    }
    return $facebookMeta;
}
// 3. Fix Twitter Card Image
add_filter( 'aioseo_twitter_tags', 'aioseo_fix_movie_poster_twitter' );
function aioseo_fix_movie_poster_twitter( $twitterMeta ) {
    if ( is_singular( 'post' ) ) {
        $poster_path = get_field( 'poster_path', get_the_ID() );
        if ( ! empty( $poster_path ) ) {
            $poster_url = 'https://image.tmdb.org/t/p/w600_and_h900_bestv2' . $poster_path;
            $twitterMeta['twitter:image'] = $poster_url;
        }
    }
    return $twitterMeta;
}

Comments

Add a Comment