-
I have seen the code on in the tutorials to automatically at the post title as the keyword, but I was wondering if it’s possible to add additional ones too?
Basically I want it to add the post title and then again with additional words as keywords/phrases
This is what I tried but to no avail –
/**
* Function to automatically update the focus keyword and additional keywords for death-notice post type
*/
function update_death_notice_keywords()
{
$death_notices = get_posts(array(
‘posts_per_page’ => -1, // Get all death-notice posts
‘post_type’ => ‘death-notice’
));foreach ($death_notices as $notice) {
$keywords = [];// Get the title (name of the deceased)
$deceased_name = strtolower($notice->post_title);
$keywords[] = $deceased_name; // Add the deceased name as the focus keyword// Add additional keywords
$additional_keywords = array(
“{$deceased_name} death notice”,
“{$deceased_name} funeral”,
“{$deceased_name} funeral details”,
“{$deceased_name} death funeral”
);$keywords = array_merge($keywords, $additional_keywords);
// Update the focus keyword and additional keywords using Rank Math functions
update_post_meta($notice->ID, ‘rank_math_focus_keyword’, $deceased_name);
update_post_meta($notice->ID, ‘rank_math_related_keywords’, implode(“, “, array_unique($keywords)));
}
}// Hook the function to run during WordPress initialization
add_action(‘init’, ‘update_death_notice_keywords’);Is it possible?
The ticket ‘I want to automate the additional keywords too?’ is closed to new replies.