I am using this code:
function the_alt_title($title= '') {
$page = get_page_by_title($title);
if ($p = get_post_meta($page->ID, "_x_entry_alternate_index_title", true)) {
$title = $p;
}
return $title;
}
add_filter('the_title', 'the_alt_title', 10, 1);
In debug.log i get
PHP Notice: Trying to get property of non-object in /var/www/html/wp-content/themes/my-child/functions.php on this line:
if ($p = get_post_meta($page->ID, "_x_entry_alternate_index_title", true)) {
How could I fix this?
get_page_by_title()
, you'll notice it will return nothing if the page was not found, so goif ( !empty($page->ID) && $p = get_post_meta($page->ID, "_x_entry_alternate_index_title", true) )