Skip to content

Instantly share code, notes, and snippets.

@mustardBees
Created June 14, 2017 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mustardBees/e57185bff7cb43cd4bcc4d7cc2f0bc9a to your computer and use it in GitHub Desktop.
Save mustardBees/e57185bff7cb43cd4bcc4d7cc2f0bc9a to your computer and use it in GitHub Desktop.
remove-product-yoast-meta.php
<?php
/*
Plugin Name: Remove Yoast SEO meta data from products
Plugin URI: https://www.iweb.co.uk/
Description: Change download URL.
Version: 1.0.0
Author: iWeb
Author URI: https://www.iweb.co.uk/
*/
if ( isset( $_GET['remove-product-yoast-meta'] ) ) {
add_action( 'template_redirect', function () {
$args = array(
'posts_per_page' => -1,
'post_type' => 'product',
);
$products = new WP_Query( $args );
if ( $products->have_posts() ) {
while ( $products->have_posts() ) {
$products->the_post();
delete_post_meta( get_the_ID(), '_yoast_wpseo_title' );
delete_post_meta( get_the_ID(), '_yoast_wpseo_metadesc' );
}
}
wp_reset_postdata();
die( 'Done.' );
} );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment