add_action('save_post', function($post_id) { // Safety checks if (wp_is_post_autosave($post_id)) return; if (wp_is_post_revision($post_id)) return; if (get_post_type($post_id) !== 'post') return; // Skip if keyword already exists $existing = get_post_meta($post_id, '_aioseo_focus_keyphrases', true); if (!empty($existing) && $existing !== '[]') return; $title = get_the_title($post_id); if (!$title) return; // STEP 1: Normalize title $keyword = strtolower($title); // STEP 2: Remove dates (multiple formats) $keyword = preg_replace('/\b\d{1,2}[\/\-\.\s]\d{1,2}[\/\-\.\s]\d{2,4}\b/', '', $keyword); $keyword = preg_replace('/\b\d{4}\b/', '', $keyword); // STEP 3: Remove stopwords $stopwords = ['the','is','and','for','to','of','in','on','at','a','an','with','by','from']; $keyword = preg_replace('/\b(' . implode('|', $stopwords) . ')\b/', '', $keyword); // STEP 4: Clean text $keyword = preg_replace('/[^a-z0-9\s]/', '', $keyword); $keyword = preg_replace('/\s+/', ' ', $keyword); $keyword = trim($keyword); // STEP 5: Limit to 3–4 words (best for SEO) $words = explode(' ', $keyword); $keyword = implode(' ', array_slice($words, 0, 4)); // STEP 6: Capitalize $keyword = ucwords($keyword); if (empty($keyword)) return; // STEP 7: AIOSEO format (IMPORTANT) $focus_data = [ [ 'keyphrase' => $keyword ] ]; // Save focus keyword update_post_meta($post_id, '_aioseo_focus_keyphrases', $focus_data); // Optional: also store as additional keyword update_post_meta($post_id, '_aioseo_keywords', $keyword); });

“The Knowledge Library”

Knowledge for All, without Barriers……….
An Initiative by: Kausik Chakraborty.

The Knowledge Library

Rapid Revision on Earth Day

Rapid Revision on Earth Day

Loading data...

 

Read More: Rapid Revision Indian Art

Sign up to Receive Awesome Content in your Inbox, Frequently.

We don’t Spam!
Thank You for your Valuable Time

Also Read  Rapid Revision Indian Art

Share this post

error: Content is protected !!