mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-30 11:42:22 +08:00
https://stackoverflow.com/questions/73147365/how-to-automatically-use-product-title-as-focus-keyword-in-rank-math
14 lines
589 B
Text
14 lines
589 B
Text
function update_focus_keywords() {
|
|
$posts = get_posts(array(
|
|
'posts_per_page' => -1,
|
|
'post_type' => 'product' // Replace post with the name of your post type
|
|
));
|
|
foreach($posts as $p){
|
|
// Checks if Rank Math keyword already exists and only updates if it doesn't have it
|
|
$rank_math_keyword = get_post_meta( $p->ID, 'rank_math_focus_keyword', true );
|
|
if ( ! $rank_math_keyword ){
|
|
update_post_meta($p->ID,'rank_math_focus_keyword',strtolower(get_the_title($p->ID)));
|
|
}
|
|
}
|
|
}
|
|
add_action( 'init', 'update_focus_keywords' );
|