[{"@context":"https:\/\/schema.org\/","@type":"BlogPosting","@id":"https:\/\/xn--adrimadiseo-beb.com\/uncategorized\/fix-yoast-seos-ai-optimize-bug-before-it-ruins-your-sites-seo\/#BlogPosting","mainEntityOfPage":"https:\/\/xn--adrimadiseo-beb.com\/uncategorized\/fix-yoast-seos-ai-optimize-bug-before-it-ruins-your-sites-seo\/","headline":"Fix Yoast SEO&#8217;s ai-optimize Bug Before It Ruins Your Site&#8217;s SEO","name":"Fix Yoast SEO&#8217;s ai-optimize Bug Before It Ruins Your Site&#8217;s SEO","description":"A friend reached out to me recently after discovering something alarming in their WordPress posts. They were using Yoast SEO Premium with the Classic Editor, ... <a title=\"Fix Yoast SEO&#8217;s ai-optimize Bug Before It Ruins Your Site&#8217;s SEO\" class=\"read-more\" href=\"https:\/\/xn--adrimadiseo-beb.com\/uncategorized\/fix-yoast-seos-ai-optimize-bug-before-it-ruins-your-sites-seo\/\" aria-label=\"M\u00e1s en Fix Yoast SEO&#8217;s ai-optimize Bug Before It Ruins Your Site&#8217;s SEO\">Leer m\u00e1s<\/a>","datePublished":"2025-06-18","dateModified":"2025-06-18","author":{"@type":"Person","@id":"https:\/\/xn--adrimadiseo-beb.com\/author\/mitzamitza-es\/#Person","name":"adrimadise\u00f1o","url":"https:\/\/xn--adrimadiseo-beb.com\/author\/mitzamitza-es\/","image":{"@type":"ImageObject","@id":"https:\/\/secure.gravatar.com\/avatar\/4f04015a3698191a873267b006e8e8789ce30b6ee841a5518a6033860d50fe16?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4f04015a3698191a873267b006e8e8789ce30b6ee841a5518a6033860d50fe16?s=96&d=mm&r=g","height":96,"width":96}},"publisher":{"@type":"Organization","name":"adrimadise\u00f1o.com","logo":{"@type":"ImageObject","@id":"https:\/\/xn--adrimadiseo-beb.com\/wp-content\/uploads\/2022\/05\/cropped-logo_adrima.png","url":"https:\/\/xn--adrimadiseo-beb.com\/wp-content\/uploads\/2022\/05\/cropped-logo_adrima.png","width":450,"height":90}},"image":{"@type":"ImageObject","@id":"https:\/\/xn--adrimadiseo-beb.com\/wp-content\/uploads\/2025\/06\/fix-yoast-SEOs-ai-optimize-bug-og.png","url":"https:\/\/xn--adrimadiseo-beb.com\/wp-content\/uploads\/2025\/06\/fix-yoast-SEOs-ai-optimize-bug-og.png","height":1080,"width":1920},"url":"https:\/\/xn--adrimadiseo-beb.com\/uncategorized\/fix-yoast-seos-ai-optimize-bug-before-it-ruins-your-sites-seo\/","about":["Uncategorized"],"wordCount":1783,"articleBody":"A friend reached out to me recently after discovering something alarming in their WordPress posts. They were using Yoast SEO Premium with the Classic Editor, and they found Yoast had been automatically inserting odd-looking CSS classes like ai-optimize-6, ai-optimize-9, directly into their content.The problem is that these classes remain permanently embedded in the posts even after disabling Yoast AI Optimize or completely deleting the plugin. This goes against expected plugin behavior\u2026 that is, when you uninstall it, it should leave no trace in your content.While these AI markers might not visually affect your site, they clutter up your source code. It could also potentially signal to AI content detectors, plagiarism checkers, and even search engines that your content was AI-generated or optimized.In this guide, I\u2019ll show you how to remove these hidden classes using a quick code snippet. I\u2019ll also explain how to apply it safely and share the SEO plugin I recommend using as an alternative to Yoast.Here are the things I will cover in this tutorial: Why These ai-optimize Classes Are Bad for SEOThe ai-optimize-{number} CSS classes are added when you use Yoast SEO Premium\u2019s AI features with the Classic Editor. They don\u2019t appear on the front end, but they\u2019re embedded in your content\u2019s HTML, which can cause problems.You can view them by visiting any post or page on your site and using the Inspect tool in your browser. Here\u2019s why I recommend removing them:They clutter your HTML: These unnecessary classes make your code harder to read and parse.They serve no purpose: They don\u2019t affect how your content looks or functions. They\u2019re just leftovers from the AI tool.They can trigger AI detection tools: Some plagiarism checkers and AI content detectors pick up these patterns and may flag your post, even if you wrote it yourself.They leave AI footprints across your site: If multiple sites use the same classes, Google might start associating that pattern with low-quality or mass-produced AI content.They increase the risk of formatting conflicts: Unknown classes could interfere with your theme or plugins down the road.There\u2019s no upside to keeping these hidden markers, and several good reasons to clean them out. The good news is that there is a quick fix, and I\u2019ll show you how to do it safely in the next section.Step 1: Make a Backup Before Making ChangesBefore we move forward, I always recommend creating a full backup of your WordPress site. It only takes a few minutes and gives you peace of mind in case anything goes wrong.I use Duplicator when I need a quick and reliable backup solution. It\u2019s the best WordPress backup plugin on the market, it is beginner-friendly, and it works great whether you\u2019re backing up or migrating your site.\u2705 On-demand and automatic WordPress backups\u2705 Safely stored in remote locations like Dropbox or Google Drive\u2705 Easy 1-click restore if something breaksFor details, see our guide on how to back up your WordPress website.Once your backup is ready, you\u2019re safe to move on to the next step, where I will show you how to fix the problem. Step 2: Add the Code Snippet to Remove ai-optimize ClassesNow that your backup is ready, it\u2019s time to clean up those ai-optimize-{number} and ai-optimize-introduction classes. I\u2019ve put together a safe and flexible code snippet that works with both the Classic Editor and the Block Editor (Gutenberg), as well as bulk edits.You don\u2019t need to touch your theme files or mess with FTP. Instead, I recommend using the WPCode plugin to add this snippet. It\u2019s what I use to manage code snippets on WordPress sites without risking anything important. (See my full WPCode review for more details.)Tip: WPCode has a limited free version that you can use for this tutorial. However, I recommend upgrading to a paid plan to unlock its full potential.If this is your first time adding custom code to your site, then you can take a look at our guide on how to add custom code snippets in WordPress without breaking your site.First, you need to install and activate the WPCode plugin. See our tutorial on installing a WordPress plugin if you need help.Once the plugin has been activated, go to the Code Snippets \u00bb + Add Snippet page and click on \u2018+ Add Custom Snippet\u2019 button under the \u2018Add Your Custom Code (New Snippet)\u2019 box.Next, you need to provide a title for your code snippet. This could be anything that helps you identify this code easily. After that, choose PHP Snippet from the \u2018Code Type\u2019 drop-down menu. Now, you need to copy and paste the following code into the Code Preview box. Here\u2019s the full code snippet:\/\/ For Classic Editor and programmatic updatesfunction strip_ai_optimize_classes($data, $postarr) {    if (empty($data['post_content']) || $data['post_type'] !== 'post') {        return $data;    }    $data['post_content'] = strip_ai_optimize_from_content($data['post_content']);    return $data;}add_filter('wp_insert_post_data', 'strip_ai_optimize_classes', 10, 2);\/\/ For Gutenberg\/Block Editorfunction strip_ai_optimize_classes_rest_insert($prepared_post, $request) {    if (isset($prepared_post-&gt;post_content) &amp;&amp; $prepared_post-&gt;post_type === 'post') {        $prepared_post-&gt;post_content = strip_ai_optimize_from_content($prepared_post-&gt;post_content);    }    return $prepared_post;}add_filter('rest_pre_insert_post', 'strip_ai_optimize_classes_rest_insert', 10, 2);\/\/ For bulk edit operations - this is the key additionfunction strip_ai_optimize_classes_bulk_edit($post_id) {    $post = get_post($post_id);    if (!$post || empty($post-&gt;post_content) || $post-&gt;post_type !== 'post') {        return;    }    $cleaned_content = strip_ai_optimize_from_content($post-&gt;post_content);    if ($cleaned_content !== $post-&gt;post_content) {        remove_action('post_updated', 'strip_ai_optimize_classes_bulk_edit');        wp_update_post(array(            'ID' =&gt; $post_id,            'post_content' =&gt; $cleaned_content        ));        add_action('post_updated', 'strip_ai_optimize_classes_bulk_edit');    }}add_action('post_updated', 'strip_ai_optimize_classes_bulk_edit');\/\/ Catch bulk operations via the bulk_edit_posts actionfunction strip_ai_optimize_classes_bulk_action($post_ids) {    if (!is_array($post_ids)) {        return;    }    foreach ($post_ids as $post_id) {        strip_ai_optimize_classes_bulk_edit($post_id);    }}add_action('bulk_edit_posts', 'strip_ai_optimize_classes_bulk_action');\/\/ Shared function to strip ai-optimize classesfunction strip_ai_optimize_from_content($content) {    if (empty($content) || !is_string($content)) {        return $content;    }    return preg_replace_callback(        '\/classs*=s*[\"']([^\"']*)[\"']\/',        function($matches) {            $classes = $matches[1];            $classes = preg_replace('\/bai-optimize-d+bs*\/', '', $classes);            $classes = preg_replace('\/s+\/', ' ', trim($classes));            if (empty($classes)) {                return '';            }            return 'class=\"' . $classes . '\"';        },        $content    );}After adding the code, scroll down to the \u2018Insertion\u2019 section.Then, select \u2018Run Everywhere\u2019 next to the \u2018Location\u2019 option.Finally, go to the top of the page and switch the status toggle in the top-right to Active, and then click on the \u2018Save Snippet\u2019 button to store your changes.Once you\u2019ve added this snippet to your site using WPCode, it will automatically strip these AI-generated classes from any post you create or update in the future.If you want to remove the ai-classes from existing content, you\u2019ll have to bulk edit your existing content.\ud83c\udf1fExpert Tip: If you\u2019re not comfortable editing code yourself, don\u2019t stress!Our team at adrimadise\u00f1o offers Emergency WordPress Support Services to help you fix issues like this quickly and safely. We can clean up your content and set up your SEO plugin the right way.Step 3: Bulk Update All Posts to Clean Up Existing AI ClassesNow that the code snippet is in place, it will automatically clean up any AI markers when you edit or publish a post. But to remove these classes from your older posts, you\u2019ll need to bulk update them.Don\u2019t worry\u2014this won\u2019t change your content. It simply triggers the filter we just added so the hidden AI classes can be stripped out safely.First, you need to go to the Posts \u00bb All Posts page in your WordPress dashboard and click \u2018Screen Options\u2019 at the top right.From here, set the number of posts per page to 999 (This is the maximum number of posts you can show on this screen) and click \u2018Apply\u2019 to load all your posts.Next, select all posts on the page by clicking the top checkbox. After that, select \u2018Edit\u2019 by clicking on the Bulk Actions dropdown, then click \u2018Apply\u2019.WordPress will now show you bulk editing options. Without changing anything else, simply click on the \u2018Update\u2019 button.WordPress will now start updating all your posts. By doing this, it will also trigger the code you saved earlier and remove the AI classes. Tip \ud83d\udca1: If you have more than 999 posts, just go to the next page and repeat this process until all posts have been updated.This will clean the ai-optimize-{number} and ai-optimize-introduction classes from all your existing posts\u2014no manual editing needed.Bonus Tip: Switching to an Alternative SEO Plugin (Better and More Powerful)Yoast SEO has been around for a long time, but lately, its innovations have slowed down. At adrimadise\u00f1o, we made the decision to switch to All in One SEO across all our sites a few years ago. It was a big move, and we documented every reason in this case study: Why We Switched from Yoast to All in One SEO.I now use All in One SEO on every personal project and all client websites. It\u2019s my go-to SEO plugin because it offers:\u2705 Comprehensive features for the AI search era (schema markup, advanced sitemaps, AI integrations, and more)\u2705 Easy setup with smart defaults and checklists\u2705 Better support for local SEO, WooCommerce, Google News, and more.If you\u2019re still on the fence, we\u2019ve made a detailed side-by-side breakdown here: Yoast SEO vs All in One SEO \u2013 Which Is the Better Plugin?Bonus SEO ResourcesWhether you\u2019re switching away from Yoast SEO or just want to tighten up your WordPress SEO strategy, here are some helpful resources to guide you. These tutorials and comparisons can save you time, avoid costly mistakes, and help you get better results from your SEO efforts:I hope this guide helped you fix the ai-optimize class issue in Yoast SEO and set your site up for better long-term results. You\u2019ve got this\u2014and if you ever need a hand, we\u2019re here to help.If you liked this article, then please subscribe to our\u00a0YouTube Channel\u00a0for WordPress video tutorials. You can also find us on\u00a0Twitter\u00a0and Facebook.                                                                                                                                                                                                                                                                                                                                                                        "},{"@context":"https:\/\/schema.org\/","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Uncategorized","item":"https:\/\/xn--adrimadiseo-beb.com\/uncategorized\/#breadcrumbitem"},{"@type":"ListItem","position":2,"name":"Fix Yoast SEO&#8217;s ai-optimize Bug Before It Ruins Your Site&#8217;s SEO","item":"https:\/\/xn--adrimadiseo-beb.com\/uncategorized\/fix-yoast-seos-ai-optimize-bug-before-it-ruins-your-sites-seo\/#breadcrumbitem"}]}]