/** * Function t]yo automatically update the focus keyword with the part of the title before " - ". * If " - " is not found, the entire title is used as the focus keyword. */ function update_focus_keywords() { $posts = get_posts(array( 'posts_per_page' => -1, 'post_type' => 'post' // replace post with the name of your post type )); foreach ($posts as $p) { $title = get_the_title($p->ID); // Check if " - " is in the title; if so, take the part before it, otherwise use the full title $focus_keyword = strpos($title, ' - ') !== false ? explode(' - ', $title)[0] : $title; update_post_meta($p->ID, 'rank_math_focus_keyword', strtolower($focus_keyword)); } } add_action('init', 'update_focus_keywords'); 1728317710_subscribe-newsletter.png - Codelist | Codelist

Leave a Reply

Your email address will not be published. Required fields are marked *