Last active
June 22, 2016 16:21
-
-
Save caercam/39dc6fa6f8ac9900eb3d841b9814b933 to your computer and use it in GitHub Desktop.
Add the movie's release date to movie title display
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Filter Yoast SEO title | |
* | |
* @param string $title | |
* | |
* @return string | |
*/ | |
function wpseo_movie_title( $title ) { | |
global $post; | |
// Don't do this in admin | |
if ( is_admin() ) { | |
return $title; | |
} | |
// Apply only to movies | |
if ( 'movie' != get_post_type( $post->ID ) ) { | |
return $title; | |
} | |
// Get release_date for WPMovieLibrary 1.x movies | |
$date = get_post_meta( $post->ID, '_wpmoly_movie_release_date', $single = true ); | |
if ( empty( $date ) ) { | |
return $title; | |
} | |
$date = date_i18n( 'Y', strtotime( $date ) ); | |
$new_title = $post->post_title . ' (' . $date . ')'; | |
$title = str_replace( $post->post_title, $new_title, $title ); | |
return $title; | |
} | |
add_filter( 'wpseo_title', 'wpseo_movie_title' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment