*update
The condition is now working but how to define $description if have custom field value also.
add_filter( 'rank_math/frontend/description', function( $description ) {
if ( is_single() && 'post' == get_post_type() && get_post_meta( get_the_ID(), 'Color', true ) ) {
$description = '{
?>
<?php echo get_post_meta(get_the_ID(),'Color',true); ?> will trend in <?php echo get_the_date('Y');?>
<?php
}';
return $description;
});
This is notworking yet and throwing error.
Hello,
Thank you for contacting Rank Math for help with setting a custom meta description on your website.
If I understand correctly, you would like the meta description to display something like: Gold will trend in 2023
I have edited the filter to create a description as above:
add_filter( 'rank_math/frontend/description', function( $description ) {
if ( is_single() && 'post' == get_post_type() && get_post_meta( get_the_ID(), 'Color', true ) ) {
$description = get_post_meta(get_the_ID(),'Color',true). " will trend in ".get_the_date('Y');
};
return $description;
});
Hope that helps. Please let us know if you have questions.
Hello,
Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.
If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.
Thank you.