Truman
1
On the separate ad page:
function hivepress_meta_description() {
if (is_singular('hp_listing')) {
$post_id = get_the_ID();
$post = get_post($post_id);
$description = $post->post_content;
// Trim the description to 160 characters
$description = mb_substr($description, 0, 160);
echo '<meta name="description" content="' . esc_attr($description) . '">';
}
}
add_action('wp_head', 'hivepress_meta_description', 10);
Truman
2
And this code will automatically generate a meta description on all pages:
function hivepress_meta_description() {
$post_id = get_the_ID();
$post = get_post($post_id);
$description = $post->post_content;
// Trim the description to 160 characters
$description = mb_substr($description, 0, 160);
echo '<meta name="description" content="' . esc_attr($description) . '">';
}
add_action('wp_head', 'hivepress_meta_description', 10);
andrii
3
Hi,
Thanks for sharing the solution with the community; I think it will benefit many.
mbm
4
Where should these codes be inserted?
andrii
5
Hi,
You can add this PHP snippet using Code Snippet plugin; please check this doc How to add custom code snippets - HivePress Help Center
system
Closed
6
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.