-
-
Save Auke1810/294ac95503b6fba5114d32c846774635 to your computer and use it in GitHub Desktop.
Solve "Item to big" error in Merchant center by removing Visual composer tags and html from description and making sure the text left is not to large.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function remove_vc_description( $attributes, $feed_id, $product_id ) { | |
//remove VC code | |
$clean_description = preg_replace("/\[(\/*)?vc_(.*?)\]/", '', $attributes['description'] ); | |
// Strip html from description attributes | |
// allow given tags with allowedTags | |
$allowedTags = ""; | |
$clean_description = strip_tags($clean_description, $allowedTags); | |
// Check if the text is larger as the max 5000 characters that Google limits | |
// If so strip the text | |
$max_length = 500; // 5000 is the max but Google also adivses 500 for a better User experience. | |
if (strlen($clean_description) > $max_length) | |
{ | |
$clean_description = wordwrap($clean_description, $max_length); | |
$clean_description = substr($clean_description, 0, strpos($clean_description, "\n")); | |
} | |
$attributes['description'] = $clean_description; | |
// IMPORTANT! Always return the $attributes | |
return $attributes; | |
} | |
add_filter( 'wppfm_feed_item_value', 'remove_vc_description', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment