add_action('shutdown', function() { if (!isset($_POST['post_ID'])) return; $post_id = intval($_POST['post_ID']); if (get_post_type($post_id) !== 'post') return; // Preskoi ako ve postoji meta opis $existing = get_post_meta($post_id, '_yoast_wpseo_metadesc', true); if (!empty($existing)) return; // Preskoi ako je ve generisano u posljednjih 20 minuta $transient_key = 'metaopis_generisan_' . $post_id; if (get_transient($transient_key)) return; $post = get_post($post_id); if (!$post || empty($post->post_content)) return; $trimmed = wp_trim_words(strip_tags($post->post_content), 200, ''); $api_key = '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'; $prompt = "Na osnovu sljedeeg teksta lanka, generii SEO meta opis na bosanskom jeziku. Opis treba biti jasan, informativan i imati najvie 160 karaktera.\n\n$trimmed"; $response = wp_remote_post('https://api.openai.com/v1/chat/completions', [ 'headers' => [ 'Content-Type' => 'application/json', 'Authorization' => 'Bearer ' . $api_key ], 'body' => json_encode([ 'model' => 'gpt-3.5-turbo', 'messages' => [ ['role' => 'user', 'content' => $prompt] ], 'max_tokens' => 100, 'temperature' => 0.7 ]) ]); if (is_wp_error($response)) return; $body = json_decode(wp_remote_retrieve_body($response), true); $meta = trim($body['choices'][0]['message']['content'] ?? ''); $meta = mb_substr($meta, 0, 160); if (!empty($meta)) { update_post_meta($post_id, '_yoast_wpseo_metadesc', $meta); set_transient($transient_key, time(), 20 * MINUTE_IN_SECONDS); error_log("? Automatski meta opis upisan za post ID $post_id."); } }); Restorani dobre volje - Zenit.ba Restorani dobre volje - Zenit.ba
8.9 C
Zenica
More
    Home Tags Restorani dobre volje

    Tag: Restorani dobre volje

    Zenica
    overcast clouds
    8.9 ° C
    8.9 °
    8.9 °
    93 %
    1.4kmh
    99 %
    čet
    11 °
    pet
    11 °
    sub
    16 °
    ned
    5 °
    pon
    6 °