MCQs on Biosphere Reserves in India
Loading quiz...
MCQ Quiz on Biosphere Reserves in India
Also Read: MCQ Quiz on Riverside Cities in India
Post Views: 6
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); });