I am trying to set the title tag for Woocommerce pages that have endpoints. I am using Yoast SEO and so far have created this:
function woocommerce_endpoint_titles( $title ) {
$sep = ' | ';
$sitetitle = get_bloginfo();
if ( is_wc_endpoint_url( 'view-order' ) ) {
$title = 'View Order'. $sep . $sitetitle;
return $title;
}
else if ( is_wc_endpoint_url( 'edit-account' ) ) {
$title = 'Edit Account'. $sep . $sitetitle;
return $title;
}
else if ( is_wc_endpoint_url( 'edit-address' ) ) {
$title = 'Edit Address'. $sep . $sitetitle;
return $title;
}
else if ( is_wc_endpoint_url( 'lost-password' ) ) {
$title = 'Lost Password'. $sep . $sitetitle;
return $title;
}
else if ( is_wc_endpoint_url( 'customer-logout' ) ) {
$title = 'Logout'. $sep . $sitetitle;
return $title;
}
else if ( is_wc_endpoint_url( 'order-pay' ) ) {
$title = 'Order Payment'. $sep . $sitetitle;
return $title;
}
else if ( is_wc_endpoint_url( 'order-received' ) ) {
$title = 'Order Received'. $sep . $sitetitle;
return $title;
}
else if ( is_wc_endpoint_url( 'add-payment-method' ) ) {
$title = 'Add Payment Method'. $sep . $sitetitle;
return $title;
}
}
add_filter( 'wpseo_title','woocommerce_endpoint_titles');
This works, but only for the endpoint pages, all other pages now don't have a title. How can I make my above code return the default title when not on an endpoint page?
Cheers,
Steve