Last active
February 19, 2024 09:45
-
-
Save Auke1810/928c039bbe25480c77bcc335362251c3 to your computer and use it in GitHub Desktop.
Create clean description attribute by removing html, VC en DIVI markup etc.
This file contains hidden or 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
/** | |
* Create clean description attribute by removing html, VC en DIVI markup etc. | |
* @param array $attributes variable is an array that contains all the product data that goes into the feed. | |
* @param Int $feed_id makes it possible to only edit a specific feed. You can find the id of a feed in the url of the Feed Editor | |
* @param Int $product_id makes it possible to select a specific product id that you want to filter. | |
* @return array. | |
*/ | |
function alter_feed_description_item( $attributes, $feed_id, $product_id ) { | |
// Remove WordPress shortcodes from Description | |
$attributes['description'] = strip_shortcodes( $attributes['description'] ); | |
// If you use Visual Composer markup in your product descrioptions you can remove Visual Composer markup with the next code. | |
$attributes['description'] = preg_replace("/\[(\/*)?vc_(.*?)\]/", '', $attributes['description'] ); | |
// To remove Divi markup in your product description use the below preg replace. | |
$attributes['description'] = preg_replace("/\[\/?et_pb.*?\]/", '', $attributes['description'] ); | |
// Only use the first 500 caracters from a string and append with ... | |
$attributes['description'] = mb_strimwidth($attributes['description'], 0, 500, "..."); | |
// IMPORTANT! Always return the $attributes | |
return $attributes; | |
} | |
add_filter( 'wppfm_feed_item_value', 'alter_feed_description_item', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you're not familiar with using filters in your wp-admin, the best and easiest way to do this is by using a plugin like "Code Snippets" (https://wordpress.org/plugins/code-snippets/). Here you can find a great video explaining the use of this plugin https://www.youtube.com/watch?v=I1_ZqnQmwJs.
After activating the Code Snippets plugin you can use the code to add the functionality.