How to copy title of WP post dynamically to focus keyword field in Yoast SEO

0 votes
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?
Feb 23, 2022 in Others by Kichu
• 19,040 points
1,319 views

1 answer to this question.

0 votes
$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();


this is a sample code like this create a loop that loops through all the post and then update the post meta 
and after that create a blank page that doesnt contain a loop and add this code in it 
$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_focusk‌​w', $title);

        echo $title . ' Meta Updated<br />';
    endwhile;
after that create a page using this page template 

answered Feb 24, 2022 by narikkadan
• 63,600 points

Related Questions In Others

0 votes
1 answer

How to echo WP SEO Yoast synonyms in PHP?

Title: "<?php echo WPSEO_Meta::get_value("title"); ?>"<br /> Description: "<?php ...READ MORE

answered Feb 24, 2022 in Others by narikkadan
• 63,600 points
728 views
0 votes
1 answer

How to retrieve the value of a text field in Flutter App?

Hi@akhtar, In your TextField, you can call one ...READ MORE

answered Sep 3, 2020 in Others by MD
• 95,460 points
1,818 views
0 votes
1 answer

how to show the <meta> values of yoast seo with some function?

check this folder : wordpress-seo\src\presenters\open-graph you can ...READ MORE

answered Feb 10, 2022 in Others by narikkadan
• 63,600 points
621 views
0 votes
1 answer

How to add a class to the <a> tag in Yoast SEO breadcrumbs?

add_filter( 'wpseo_breadcrumb_single_link', 'ss_breadcrumb_single_link', 10, 2 ); function ss_breadcrumb_single_link( ...READ MORE

answered Feb 22, 2022 in Others by narikkadan
• 63,600 points
1,576 views
0 votes
1 answer

How to Access Yoast SEO tags in Wordpress API Callback

use rest api to request for the ...READ MORE

answered Feb 12, 2022 in Others by narikkadan
• 63,600 points
1,851 views
0 votes
1 answer

Yoast SEO (WordPress Plugin) - Get plugin generated data manually

get_post_meta(), use this to get the meta ...READ MORE

answered Feb 11, 2022 in Others by narikkadan
• 63,600 points
1,520 views
0 votes
1 answer

Simple question regarding PHP, Wordpress & Yoast SEO

the way the search engine displays your ...READ MORE

answered Feb 14, 2022 in Others by narikkadan
• 63,600 points
519 views
0 votes
1 answer

how can I change yoast seo generated sitemap file URL?

plugins/wordpress-seo/inc/sitemaps/class-sitemaps-router.php go to this directory and change the ...READ MORE

answered Feb 22, 2022 in Others by narikkadan
• 63,600 points
3,603 views
0 votes
1 answer

How to echo WP SEO Yoast synonyms in PHP?

 the meta_key in wp_postmeta table is _yoast_wpseo_keyword ...READ MORE

answered Feb 10, 2022 in Others by narikkadan
• 63,600 points
1,145 views
0 votes
1 answer

How to add meta keyword in wordpress using yoast seo plugin.?

if you dont want to use code ...READ MORE

answered Feb 12, 2022 in Others by narikkadan
• 63,600 points
1,017 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP