Filter out external links in the WooCommerce product description functions.php
I have an online marketplace powered by WooCommerce and need to prevent vendors from adding links to their websites or Etsy URLs in the product descriptions.
Is there a way to filter out external links in the product description and short description in functions.php?
-
Used the plugin Real-Time Find & Replace to filter out Etsy links in real-time, but this doesn’t resolve it when vendors link to other channels or their website in the product description.
-
Need to keep HTML available for shortcodes or other features. Just need to filter out external links only.
-
I still want to allow external links in WordPress posts. Only need to filter out external links for WooCommerce descriptions and short descriptions.
Update: I just found this filter for WordPress posts. So it would be something link this, but for WooCommerce descriptions and short descriptions:
add_filter( 'the_content', 'filter_the_content_in_the_main_loop' );
function filter_the_content_in_the_main_loop( $content ) {
if ( is_single() ) {
$content = preg_replace(array('"<a href(.*?)>"', '"</a>"'), array('',''), $content);
}
return $content;
}
Leave an answer
You must login or register to add a new answer .