-
Hi RankMath support,
Based on this article I tried to automate the Insertion of Focus Keyword for EDD Products.
https://rankmath.com/kb/how-to-automate-the-insertion-of-focus-keyword/
First, I created the rank-math.php at the theme folder.
Then I added this code to it.
<?php
/**
* Function to automatically update the focus keyword with the post tags, if no focus keyword is set
*/
function update_focus_keywords()
{
$posts = get_posts(array(
'posts_per_page' => 100,
'post_type' => 'download' //replace post with the name of your post type
));
foreach ($posts as $p) {
$keywords = [];
if (get_the_tags($p->ID)) {
foreach ((get_the_tags($p->ID)) as $tag) {
$keywords[] = strtolower($tag->name);
}
if (!get_post_meta($p->ID, 'rank_math_focus_keyword', true)) {
update_post_meta($p->ID, 'rank_math_focus_keyword', implode(", ", array_unique($keywords)));
}
}
}
}
add_action('init', 'update_focus_keywords');?>
But after the download update, the keyword is not updated.
———————————————————————–
And one more question:
is there anyway to add KKstar ratings to EDD product schema in rank math?
Can you help me?
The ticket ‘Automatically Use the EDD Download Title as the Focus Keyword’ is closed to new replies.