Skip to content

Instantly share code, notes, and snippets.

@sonnetmia
Created June 24, 2016 13:36
Show Gist options
  • Save sonnetmia/7a8dad2af9beab24f53e76638d1c5838 to your computer and use it in GitHub Desktop.
Save sonnetmia/7a8dad2af9beab24f53e76638d1c5838 to your computer and use it in GitHub Desktop.
Woocommerce Post Excerpt Lenght Control For Short Description
function string_limit_words($string, $word_limit)
{
$words = explode(' ', $string, ($word_limit + 1));
if(count($words) > $word_limit)
array_pop($words);
return implode(' ', $words);
}
function hook_some_content_into_content_product_page(){
$excerpt = get_the_excerpt();
$limitedcontent = strip_tags($excerpt);
echo '<p class="homeexcerpt">'.string_limit_words($limitedcontent,10).'</p>';
return true;
}
add_action('woocommerce_after_shop_loop_item_title', 'hook_some_content_into_content_product_page' , 20 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment