I have around 1K posts in my blog. I use Yoast SEO Wordpress Plugin. All my posts doesn't has focus keyword added. Is there any way possible I can add title of the post dynamically to focus keyword field instead of copy paste one by one?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Yoast Focus Keywords is a post meta, you can create a loop that loops through all the posts and then update the post meta with get_the_title();
Sample code:
$title = get_the_title();
$args = array('posts_per_page' => -1, 'post_type' => 'post');
$posts = new WP_Query($args);
foreach($posts as $post){
update_post_meta($post->ID, '_yoast_wpseo_focuskw', $title);
}
wp_reset_postdata();
You can add the code inside your functions.php or create a page template with the code.
Update:
Create a blank page template that doesn't contain a loop, then add the below code into the file and create a page using this page template.
$posts_query = new WP_Query(
array(
'post_type' => 'post',
'posts_per_page' => -1
)
);
while($posts_query->have_posts()) : $posts_query->the_post();
$title = get_the_title();
$post_id = get_the_ID();
update_post_meta($post_id, '_yoast_wpseo_focuskw', $title);
echo $title . ' Meta Updated<br />';
endwhile;
Visit the page using the page template and it should go through each post and display "TITLE Meta Updated" each time it goes through a post.