Support » Plugin: Pixel Caffeine » description is over maximum character limit; can we ‘limit characters’?

  • Resolved onlyshawn

    (@onlyshawn)


    our page uses several “click to expand” buttons in the short product description to include extra information that I want up there but don’t want shown unless someone wants to see it. Unfortunately, due to these extra words, all of our products hit up against facebook’s 5k character limit. Is there a way to include a limit so that pixel caffeine is only sending over the first 1k characters or something? Or even, better yet, a break where it only sends over information BEFORE the break?

    • This topic was modified 2 months ago by onlyshawn.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Antonino Scarfì

    (@antoscarface)

    Hi,

    you can use an hook in order to adjust the description as you want. Here the hook:

    
    add_filter('aepc_feed_item', function($fields, $item) {
    	$product_id = $item->get_id();
    	
    	// EDIT HERE
    	$fields['g:description'] = wp_trim_words($fields['g:description'], 200);
    	// END EDIT HERE
    	
    	return $fields;
    }, 10, 2);
    
    

    In this example, I’m using the function wp_trim_words, in order to avoid to cut the last words hardly and to trim the description by words. 200 is the number of words to keep and it’s an average to keep under about 1k characters.

    Instead, if you want to cut hardly, just use:

    
    $fields['g:description'] = substr($fields['g:description'], 0, 1000);
    

    Use this hook at the end of the functions.php file of your current theme or in a new plugin.

    excellent, thanks mate, i really appreciate the help.

    Plugin Author Antonino Scarfì

    (@antoscarface)

    You’re very welcome! 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.