Last active
August 29, 2015 14:04
-
-
Save MickeyKay/6790b1c366a4b3bacabf to your computer and use it in GitHub Desktop.
[WordPress] Override the default post title with a custom field.
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
// Only override the title on the front-end. | |
if ( ! is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) { | |
add_filter( 'the_title', 'PREFIX_override_post_title', 10, 2 ); | |
} | |
/** | |
* Override the_title() with a custom field if it is specified. | |
* | |
* @param string $title Original post title. | |
* | |
* @return string $title Update post title. | |
*/ | |
function PREFIX_override_post_title( $title, $id ) { | |
$custom_title = get_post_meta( $id, 'custom_title', true ); | |
if ( ! empty( $custom_title ) ) { | |
$title = $custom_title; | |
} | |
return $title; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment