Created
July 7, 2024 14:49
-
-
Save shameemreza/49c3c40b24391a883a3fe234f8e201bd to your computer and use it in GitHub Desktop.
Automatically set the focus keyword with product title in Rank Math SEO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment