`
$metadescription = wp_trim_words( get_the_content(), 55, '');
add_post_meta($post_id, 'meta_description', '$metadescription', true);`
but output is $metadescription
anyone help me please
`$metadescription = wp_trim_words( get_the_content(), 55, '');
add_post_meta($post_id, 'meta_description', '$metadescription', true);``
CodePudding user response:
Try out the below code:
For the variable, you don't need to use ''
for that.
$metadescription = wp_trim_words( get_the_content(), 55, '');
add_post_meta($post_id, 'meta_description', $metadescription , true);
CodePudding user response:
First, make sure that get_the_content
is returning the content you want and $meta_description
isn't null.
Try This:
add_post_meta($post_id, 'meta_description', '' . $meta_description . '', true);
CodePudding user response:
You're enclosing the variable $metadescription in single quotes.Single quotes prevent variables from being evaluated and instead treat the enclosed string literally Try this :
$metadescription = wp_trim_words( get_the_content(), 55, '');
add_post_meta($post_id, 'meta_description', "$metadescription", true);