function get_yoast_brand() {
$string = '';
if ( is_single() ) {
$string = get_post_meta( get_the_ID(), '_brand', true ) ?? __( 'Default Brand', 'textdomain' );
}
return $string;
}
// Define the action for register yoast_variable replacments.
function register_custom_yoast_variables() {
wpseo_register_var_replacement( '%%Brand%%', 'get_yoast_brand', 'advanced', __( 'Description of this field', 'textdomain' ) );
}
// Add action.
add_action( 'wpseo_register_extra_replacements', 'register_custom_yoast_variables' );