Advertisement
jaideep06

Autogenerate focus keyword

Feb 6th, 2025
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.54 KB | None | 0 0
  1. function update_focus_keyword_for_product($product_id) {
  2.     if (!$product_id || get_post_type($product_id) !== 'product') {
  3.         return;
  4.     }
  5.  
  6.     $title = get_the_title($product_id);
  7.     if (!$title) {
  8.         return;
  9.     }
  10.  
  11.     // Convert commas to HTML entities to prevent splitting
  12.     $title = str_replace(',', ',', $title);
  13.     $title = str_replace('×', 'x', $title);
  14.  
  15.     // Store the exact title (with modified comma) as the focus keyword
  16.     update_post_meta($product_id, 'rank_math_focus_keyword', $title);
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement