{\rtf1\ansi\ansicpg1252\cocoartf2822 \cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 Helvetica;} {\colortbl;\red255\green255\blue255;} {\*\expandedcolortbl;;} \paperw11900\paperh16840\margl1440\margr1440\vieww11520\viewh8400\viewkind0 \pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural\partightenfactor0 \f0\fs24 \cf0

\uc0\u9989 Settings saved.

';\ \}\ $key = get_option('ai_seo_openai_key');\ $model = get_option('ai_seo_model', 'gpt-4o-mini');\ ?>\
\

AI SEO Optimizer Settings

\
\ \ \ \ \ \ \ \ \ \
OpenAI API Key
Model\ \
\ \
\

Tip: You can also use xAI Grok API \'97 just change the endpoint in the code if needed.

\
\ ID, '_ai_seo_primary_keyword', true);\ ?>\
\

Primary Keyword / Topic
\ \

\ \ \ \
\
\ \ \ post_content);\ $title = $post->post_title;\ $excerpt = $post->post_excerpt ?: substr($content, 0, 160);\ $word_count = str_word_count($content);\ $title_len = strlen($title);\ $desc_len = strlen($excerpt);\ \ $checks = [\ 'title_length' => ($title_len >= 40 && $title_len <= 60) ? 10 : 3,\ 'keyword_in_title' => (stripos($title, $keyword) !== false) ? 10 : 0,\ 'keyword_front' => (stripos($title, $keyword) < 30) ? 5 : 0,\ 'meta_desc' => ($desc_len >= 120 && $desc_len <= 160) ? 10 : 4,\ 'word_count' => ($word_count >= 600) ? 15 : ($word_count >= 300 ? 8 : 0),\ 'headings' => (preg_match_all('/post_content) >= 3) ? 8 : 2,\ 'keyword_density' => $keyword ? min(10, round(substr_count(strtolower($content), strtolower($keyword)) / max(1, $word_count/100))) : 0,\ 'first_paragraph' => (stripos($content, $keyword) < 300) ? 7 : 0,\ 'images_alt' => (preg_match_all('/alt=["\\'](.*?)["\\']/i', $post->post_content, $m) && count($m[1]) > 0) ? 5 : 0,\ 'internal_links' => (preg_match_all('/post_content) >= 3) ? 5 : 0,\ 'eeat' => 8, // Base \'96 AI will refine\ ];\ \ $score = array_sum($checks);\ $score = min(100, max(0, $score));\ \ // === AI ANALYSIS (2026 guidelines) ===\ $api_key = get_option('ai_seo_openai_key');\ $model = get_option('ai_seo_model', 'gpt-4o-mini');\ $ai_suggestions = '';\ \ if ($api_key) \{\ $prompt = "You are an expert SEO consultant using Google's 2026 guidelines (E-E-A-T, Helpful Content Update, AI Overviews optimization).\\n\\n";\ $prompt .= "Page Title: $title\\n";\ $prompt .= "Primary Keyword: $keyword\\n";\ $prompt .= "Content length: $word_count words\\n\\n";\ $prompt .= "Analyze this page and return **valid JSON only** with this structure:\\n";\ $prompt .= '\{"overall_score": '.$score.', "title_suggestion": "...", "meta_description": "...", "key_improvements": ["..."], "eeat_tips": "...", "ai_overview_optimized": "yes/no"\}';\ \ $response = wp_remote_post('https://api.openai.com/v1/chat/completions', [\ 'headers' => [\ 'Authorization' => 'Bearer ' . $api_key,\ 'Content-Type' => 'application/json'\ ],\ 'body' => json_encode([\ 'model' => $model,\ 'messages' => [['role' => 'user', 'content' => $prompt]],\ 'temperature' => 0.7,\ 'max_tokens' => 800\ ]),\ 'timeout' => 25\ ]);\ \ if (!is_wp_error($response)) \{\ $body = json_decode(wp_remote_retrieve_body($response), true);\ $ai_text = $body['choices'][0]['message']['content'] ?? '';\ $ai_json = json_decode($ai_text, true) ?: [];\ \ $ai_suggestions = '

\uc0\u55358 \u56598 AI Recommendations (2026)

';\ $ai_suggestions .= '

Optimized Title:
'.esc_html($ai_json['title_suggestion'] ?? '').'

';\ $ai_suggestions .= '

Meta Description:
'.esc_html($ai_json['meta_description'] ?? '').'

';\ $ai_suggestions .= '';\ \}\ \}\ \ // Output\ echo '
';\ echo '

SEO Score: '.$score.'/100

';\ echo $ai_suggestions ?: '

Add your OpenAI key in Settings for AI suggestions.

';\ echo '
';\ \ update_post_meta($post_id, '_ai_seo_primary_keyword', $keyword);\ wp_die();\ \});}