Hide created product in Yoast feed
When a store agent creates a custom product on the fly during a phone order using the Phone Orders for WooCommerce plugin, a new product is generated dynamically. This product is typically a one‑off item that should not be indexed by search engines or appear in XML sitemaps, Google Merchant Center feeds, or other public product listings. Unless explicitly prevented, the Yoast SEO plugin will include these temporary products in its generated feeds. This guide explains how to automatically hide all custom products created via Phone Orders from Yoast feeds, keeping search results clean and preventing confusion for customers browsing the catalogue.
The Solution: Add a Noindex Meta Flag to Every Custom Product
The Phone Orders for WooCommerce plugin fires a custom action hook called wpo_create_custom_product every time a custom product is created. This hook passes two parameters: the ID of the newly created product ($post_id) and the product object ($product).
By attaching a simple function to this hook, we can add the Yoast SEO “meta‑robots‑noindex” flag to the product immediately after its creation. The flag is stored as custom post meta (a key‑value pair in the database). When Yoast SEO builds its sitemap or feed, it checks this meta key. If the value is 1, the product is excluded from the feed.
Here is the complete code snippet:
|
1 2 3 4 |
//don't show product in Yoast feed! add_action('wpo_create_custom_product', function($post_id, $product){ update_post_meta($post_id, "_yoast_wpseo_meta-robots-noindex", 1); },10,2); |
Choose where to add the code
You have two reliable options for adding custom PHP code:
- Option A (Recommended): Use a code snippet plugin. The free Code Snippets plugin (available at wordpress.org) is the safest method. It allows you to add, activate, and deactivate code snippets without ever touching your theme files.
- Option B: Add to your child theme’s
functions.phpfile. If you are already comfortable editing theme files, add the code to your active child theme’sfunctions.phpfile. Never add custom code directly to a parent theme, because it will be lost when the theme is updated.