This article introduces how to automatically include the same string as the title at the beginning of the meta description using the PHP language and WordPress API. This is one of the SEO measures I used to do. Uses the All in One SEO Pack filter hook.
The following example is code that includes the same string as the title at the beginning of the meta description. If the meta description already contains the title, it cancels.
Copy and paste the following PHP into header.php or functions.php.
<!--?php
function my_description($description) {
global $post;
if ( strpos( $description , $post--->post_title) !== false) {
// do nothing
} else {
if ( substr( $post->post_title , -1) == "ใ"){
$description = $post->post_title."".$description;
} else {
$description = $post->post_title."ใ".$description;
}
}
return $description;
}
add_filter('aioseop_description', 'my_description');
?>