rakeshr

remove VC code from WordPress posts

Jun 29th, 2020
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1. /** add this to your function.php child theme to remove ugly short code on excerpt */
  2. /** add by Paolo Rudelli aka Paul Corneille 09-06-2014 */
  3. if(!function_exists('remove_vc_from_excerpt'))  {
  4.     function remove_vc_from_excerpt( $excerpt ) {
  5.         $patterns = "/\[[\/]?vc_[^\]]*\]/";
  6.         $replacements = "";
  7.         return preg_replace($patterns, $replacements, $excerpt);
  8.     }
  9. }
  10. /** * Original elision function mod by Paolo Rudelli */
  11. if(!function_exists('qode_excerpt')) {
  12. /** Function that cuts post excerpt to the number of word based on previosly set global * variable $word_count, which is defined in qode_set_blog_word_count function */
  13. function qode_excerpt() {
  14. global $qode_options_elision, $word_count, $post;
  15. $word_count = isset($word_count) && $word_count != "" ? $word_count : $qode_options_elision['number_of_chars'];
  16. $post_excerpt = $post->post_excerpt != "" ? $post->post_excerpt : strip_tags($post->post_content);
  17. $clean_excerpt = strpos($post_excerpt, '...') ? strstr($post_excerpt, '...', true) : $post_excerpt;
  18. /** add by PR */
  19. $clean_excerpt = strip_shortcodes(remove_vc_from_excerpt($clean_excerpt));
  20. /** end PR mod */
  21. $excerpt_word_array = explode (' ',$clean_excerpt);
  22. $excerpt_word_array = array_slice ($excerpt_word_array, 0, $word_count);
  23. $excerpt = implode (' ', $excerpt_word_array).'...'; echo ''.$excerpt.'';
  24. }
  25. }
Add Comment
Please, Sign In to add comment