/** * Displays the Widget * */ function widget($args, $instance) { extract($args); extract($instance); if (is_multisite()) { switch_to_blog($blog_id); } $output = ''; global $wpdb; $request = $wpdb->prepare("SELECT " . $wpdb->prefix . "posts.*\n FROM " . $wpdb->prefix . "posts\n WHERE post_type='{$post_type}' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 0,%d", (int) $limit); $results = $wpdb->get_results($request); $results = $wpdb->get_results($request); if (!empty($results)) { $output = '<ul>'; foreach ($results as $post) { $post_link = get_permalink($post->ID); if (!empty($post->post_excerpt)) { $excerpt = $post->post_excerpt; } else { $excerpt = $post->post_content; $excerpt = strip_shortcodes($excerpt); $excerpt = strip_tags($excerpt); } $excerpt = $this->truncate_string($excerpt, $excerpt_length); $image = ""; if (has_post_thumbnail($post->ID)) { $thumb_id = get_post_thumbnail_id($post->ID); $image_data = wp_get_attachment_image_src($thumb_id, 'full'); if (is_array($image_data)) { $image_src = plugins_url('timthumb.php', __FILE__) . "?src=" . $image_data[0] . "&w={$imagew}&h={$imageh}&zc=1&a=t"; $image = "<img src='{$image_src}' alt='{$post->post_title}' />"; } } $template = trim($template); if (empty($template)) { $output .= '<li>'; $output .= '<a rel="bookmark" href="' . $post_link . '"><strong class="title">' . $post->post_title . '</strong></a>'; $output .= '</li>'; } else { $tokens = array("{title}", "{link}", "{image}", "{excerpt}"); $data = array($post->post_title, $post_link, $image, $excerpt); $matches = null; $returnValue = preg_match_all('/%%(\\w+)%%/', $template, $matches); if (is_array($matches[1])) { foreach ($matches[1] as $customfield) { $tokens[] = "%%{$customfield}%%"; $data[] = get_post_meta($post->ID, $customfield, true); } } $output .= '<li>' . str_replace($tokens, $data, $template) . '</li>'; } } $output .= '</ul>'; } if (is_multisite()) { restore_current_blog(); } echo $before_widget . $before_title . $title . $after_title; echo $output . $after_widget; }
function porto_get_excerpt($limit = 45, $more_link = true) { global $porto_settings; if (!$limit) { $limit = 45; } if (has_excerpt()) { $content = strip_tags(strip_shortcodes(get_the_excerpt())); } else { $content = strip_tags(strip_shortcodes(get_the_content())); } $content = explode(' ', $content, $limit); if (count($content) >= $limit) { array_pop($content); if ($more_link) { $content = implode(" ", $content) . '... '; } else { $content = implode(" ", $content) . ' [...]'; } } else { $content = implode(" ", $content); } if ($porto_settings['blog-excerpt-type'] == 'html') { $content = apply_filters('the_content', $content); $content = do_shortcode($content); } if ($more_link) { $content .= ' <a class="read-more" href="' . esc_url(apply_filters('the_permalink', get_permalink())) . '">' . __('read more', 'porto') . ' <i class="fa fa-angle-right"></i></a>'; } if ($porto_settings['blog-excerpt-type'] != 'html') { $content = '<p class="post-excerpt">' . $content . '</p>'; } return $content; }
/** * Smart Excerpt * * Returns an excerpt which is not longer than the given length and always * ends with a complete sentence. If first sentence is longer than length, * it will add the standard ellipsis… Length is the number of characters. * * Usage: <?php smart_excerpt(450); > * * http://www.distractedbysquirrels.com/blog/wordpress-improved-dynamic-excerpt */ function smart_excerpt($length, $postId = false) { if ($postId) { $post = get_post($postId); $text = $post->post_excerpt; } else { global $post; $text = $post->post_excerpt; } if ('' == $text) { if ($postId) { $text = $post->post_content; } else { $text = get_the_content(''); } $text = apply_filters('the_content', $text); $text = str_replace(']]>', ']]>', $text); } $text = strip_shortcodes($text); $text = wp_strip_all_tags($text, true); if (empty($length)) { $length = 300; } $text = substr($text, 0, $length); $excerpt = nucleus_reverse_strrchr($text, '.', 1); if ($excerpt) { echo apply_filters('the_excerpt', $excerpt); } else { echo apply_filters('the_excerpt', $text . '…'); } }
function remove_shortcode_from_index($content) { if (is_home()) { $content = strip_shortcodes($content); } return $content; }
/** * Allows post excerpts to contain HTML tags * @since mantra 1.8.7 * @return string Excerpt with most HTML tags intact */ function mantra_trim_excerpt($text) { global $mantra_excerptwords; global $mantra_excerptcont; global $mantra_excerptdots; $raw_excerpt = $text; if ('' == $text) { //Retrieve the post content. $text = get_the_content(''); //Delete all shortcode tags from the content. $text = strip_shortcodes($text); $text = apply_filters('the_content', $text); $text = str_replace(']]>', ']]>', $text); $allowed_tags = '<a>,<img>,<b>,<strong>,<ul>,<li>,<i>,<h1>,<h2>,<h3>,<h4>,<h5>,<h6>,<pre>,<code>,<em>,<u>,<br>,<p>'; $text = strip_tags($text, $allowed_tags); $words = preg_split("/[\n\r\t ]+/", $text, $mantra_excerptwords + 1, PREG_SPLIT_NO_EMPTY); if (count($words) > $mantra_excerptwords) { array_pop($words); $text = implode(' ', $words); $text = $text . ' ' . $mantra_excerptdots . ' <a href="' . get_permalink() . '">' . $mantra_excerptcont . ' <span class="meta-nav">→ </span>' . '</a>'; } else { $text = implode(' ', $words); } } return apply_filters('wp_trim_excerpt', $text, $raw_excerpt); }
function sb_cl_get_the_excerpt($id = false) { global $post; $old_post = $post; if ($id != $post->ID) { $post = get_page($id); } if (!($excerpt = trim($post->post_excerpt))) { $excerpt = $post->post_content; if (!($more_pos = strpos($excerpt, '<!--more-->'))) { if (function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage')) { $excerpt = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($excerpt); } $excerpt = strip_shortcodes($excerpt); $excerpt = apply_filters('the_content', $excerpt); $excerpt = str_replace(']]>', ']]>', $excerpt); $excerpt = strip_tags($excerpt); $excerpt_length = apply_filters('excerpt_length', 55); $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]'); $words = preg_split("/[\n\r\t ]+/", $excerpt, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY); if (count($words) > $excerpt_length) { array_pop($words); $excerpt = implode(' ', $words); $excerpt = $excerpt . $excerpt_more; } else { $excerpt = implode(' ', $words); } } else { $excerpt = substr($excerpt, 0, $more_pos); } } $post = $old_post; return $excerpt; }
function fb_strip_and_format_desc($post) { $desc_no_html = ""; $desc_no_html = strip_shortcodes($desc_no_html); // Strip shortcodes first in case there is HTML inside the shortcode $desc_no_html = wp_strip_all_tags($desc_no_html); // Strip all html $desc_no_html = trim($desc_no_html); // Trim the final string, we may have stripped everything out of the post so this will make the value empty if that's the case // Check if empty, may be that the strip functions above made excerpt empty, doubhtful but we want to be 100% sure. if (empty($desc_no_html)) { $desc_no_html = $post->post_content; // Start over, this time with the post_content $desc_no_html = strip_shortcodes($desc_no_html); // Strip shortcodes first in case there is HTML inside the shortcode $desc_no_html = str_replace(']]>', ']]>', $desc_no_html); // Angelo Recommendation, if for some reason ]]> happens to be in the_content, rare but We've seen it happen $desc_no_html = wp_strip_all_tags($desc_no_html); $excerpt_length = apply_filters('excerpt_length', 55); $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]'); $desc_no_html = wp_trim_words($desc_no_html, $excerpt_length, $excerpt_more); $desc_no_html = trim($desc_no_html); // Trim the final string, we may have stripped everything out of the post so this will make the value empty if that's the case } $desc_no_html = str_replace(array("\r\n", "\r", "\n"), ' ', $desc_no_html); // I take it Facebook doesn't like new lines? return $desc_no_html; }
/** * Custom excerpt * * @param $post_excerpt * * @return mixed|string */ function easy_event_the_excerpt($post_excerpt) { $post_id = get_the_ID(); $post = get_post($post_id); $excerpt_temp = $post->post_excerpt; if ($excerpt_temp == '') { $excerpt_temp = get_post_meta($post_id, 'easy_event_description', true); } if ($excerpt_temp == '') { $excerpt_temp = strip_tags($post->post_content); } $excerpt_temp = strip_shortcodes($excerpt_temp); /** * Excerpt length */ $excerpt_length = get_option('easy_event_excerpt_length'); if ($excerpt_length == false) { $excerpt_length = 250; } $excerpt_length += 5; if (mb_strlen($excerpt_temp) > $excerpt_length) { $subex = mb_substr($excerpt_temp, 0, $excerpt_length - 5); $exwords = explode(' ', $subex); $excut = -mb_strlen($exwords[count($exwords) - 1]); if ($excut < 0) { return mb_substr($subex, 0, $excut) . '[...]'; } else { return $subex . '[...]'; } } else { return $excerpt_temp; } }
/** * Clean post description text in preparation for Open Graph protocol description or Facebook post caption|description * * @since 1.1 * @uses strip_shortcodes() * @uses wp_trim_words() * @param string $description description text * @return string description text passed through WordPress Core description cleaners, possibly trimmed */ public static function clean_description($description, $trimmed = true) { $description = trim($description); if (!$description) { return ''; } // basic filters from wp_trim_excerpt() that should apply to both excerpt and content // note: the_content filter is so polluted with extra third-party stuff we purposely avoid to better represent page content $description = strip_shortcodes($description); // remove any shortcodes that may exist, such as an image macro $description = str_replace(']]>', ']]>', $description); $description = trim($description); if (!$description) { return ''; } if ($trimmed) { // use the built-in WordPress function for localized support of words vs. characters // pass in customizations based on WordPress with publisher overrides $description = wp_trim_words($description, apply_filters('facebook_excerpt_length', apply_filters('excerpt_length', 55)), apply_filters('facebook_excerpt_more', __('…'))); } else { $description = wp_strip_all_tags($description); } if ($description) { return $description; } return ''; }
function fb_description() { global $post; if (!empty($post->post_excerpt)) { $description = $post->post_excerpt; } else { $description = trim(strip_shortcodes(strip_tags($post->post_content))); $pos0 = strpos($description, '.') + 1; $pos0 = $pos0 === false ? strlen($description) : $pos0; $pos = strpos(substr($description, $pos0), '.'); if ($pos < 0 || $pos === false) { $pos = strlen($description); } else { $pos = $pos + $pos0; } $description = str_replace("\n", "", substr($description, 0, $pos)); $description = str_replace("\r", "", $description); $description = str_replace("\"", "'", $description); $description = nl2br($description); } if (is_front_page()) { $description = get_bloginfo('description'); } return $description; }
public function register_meta_tags() { add_action('wp_head', function () { if (is_singular() && false == post_password_required()) { if ('' == ($description = get_the_excerpt())) { $description = wp_trim_words(esc_html(strip_shortcodes(get_the_content())), 20, '...'); } } elseif (is_category() && '' != category_description()) { $description = category_description(); } elseif (is_tag() && '' != term_description()) { $description = term_description(); } else { $description = get_bloginfo('description'); } $description = esc_attr($description); echo "<meta name=\"description\" content=\"{$description}\" />\n"; echo "<meta name=\"og:description\" content=\"{$description}\" />\n"; if (is_singular() && false == post_password_required() && has_post_thumbnail()) { list($image, $width, $height) = wp_get_attachment_image_src(get_post_thumbnail_id(), 'facebook'); } else { $image = apply_filters('', $this->get_theme_assets_url() . '/images/logo-fb.png'); } $image = esc_url($image); echo "<meta name=\"og:image\" content=\"{$image}\" />\n"; echo "<meta name=\"twitter:image\" content=\"{$image}\" />\n"; }); }
function jl_brd_dashboard_recent_drafts($drafts = false) { if (!$drafts) { $drafts_query = new WP_Query(array('post_type' => 'any', 'post_status' => array('draft', 'pending'), 'posts_per_page' => 150, 'orderby' => 'modified', 'order' => 'DESC')); $drafts =& $drafts_query->posts; } if ($drafts && is_array($drafts)) { $list = array(); foreach ($drafts as $draft) { $url = get_edit_post_link($draft->ID); $title = _draft_or_post_title($draft->ID); $last_id = get_post_meta($draft->ID, '_edit_last', true); $last_user = get_userdata($last_id); $last_modified = '<i>' . esc_html($last_user->display_name) . '</i>'; $item = '<h4><a href="' . $url . '" title="' . sprintf(__('Edit ?%s?'), esc_attr($title)) . '">' . esc_html($title) . '</a>' . '<abbr> ' . $draft->post_status . ' ' . $draft->post_type . '</abbr>' . '<abbr style="display:block;margin-left:0;">' . sprintf(__('Last edited by %1$s on %2$s at %3$s'), $last_modified, mysql2date(get_option('date_format'), $draft->post_modified), mysql2date(get_option('time_format'), $draft->post_modified)) . '</abbr></h4>'; if ($the_content = preg_split('#\\s#', strip_shortcodes(strip_tags($draft->post_content), 11, PREG_SPLIT_NO_EMPTY))) { $item .= '<p>' . join(' ', array_slice($the_content, 0, 10)) . (10 < count($the_content) ? '…' : '') . '</p>'; } $list[] = $item; } ?> <ul> <li><?php echo join("</li>\n<li>", $list); ?> </li> </ul> <?php } else { _e('There are no drafts at the moment'); } }
function postExcerptCallback($matches) { $pageContent = strip_tags($this->page->post_content); //return "blah" .$exLength; if ($this->page->post_excerpt == "") { //if there's no excerpt applied to the post, extract one //$postCallback->pageContent = strip_tags($page->post_content); //$str = preg_replace_callback('#\[ *post_excerpt *(length=[\'|\"]([^\'\"]*)[\'|\"])? *\]#', array(&$postCallback, 'postExcerptCallback'), $str); if (isset($matches[2])) { $exLength = intval($matches[2]); } else { $exLength = 250; } //return "blah"; if (strlen($pageContent) > $exLength) { return strip_shortcodes(substr($pageContent, 0, $exLength)) . "..."; //clean up and return excerpt } else { return strip_shortcodes($pageContent); } } else { //if there is a post excerpt just use it and don't generate our own /* if(isset($matches[2])){//uncomment this if/else statement if you want the manual excerpt to be trimmed to the passed in length $exLength = intval($matches[2]); return substr($this->page->post_excerpt, 0, $exLength); }else{ return $this->page->post_excerpt; } */ return $this->page->post_excerpt; } }
function swp_get_excerpt_by_id($post_id) { // Check if the post has an excerpt if (has_excerpt()) { $the_post = get_post($post_id); //Gets post ID $the_excerpt = $the_post->post_excerpt; // If not, let's create an excerpt } else { $the_post = get_post($post_id); //Gets post ID $the_excerpt = $the_post->post_content; //Gets post_content to be used as a basis for the excerpt } $excerpt_length = 100; //Sets excerpt length by word count $the_excerpt = strip_tags(strip_shortcodes($the_excerpt)); //Strips tags and images $the_excerpt = str_replace(']]>', ']]>', $the_excerpt); $the_excerpt = strip_tags($the_excerpt); $excerpt_length = apply_filters('excerpt_length', 100); $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]'); $words = preg_split("/[\n\r\t ]+/", $the_excerpt, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY); if (count($words) > $excerpt_length) { array_pop($words); // array_push($words, '…'); $the_excerpt = implode(' ', $words); } $the_excerpt = preg_replace("/\r|\n/", "", $the_excerpt); return $the_excerpt; }
function de_excerpt($excerpt, $content, $length = 0) { if (strlen($excerpt)) { $length = $length == 0 ? strlen($excerpt) : $length; if (strlen($excerpt) > $length) { $result = mb_substr($excerpt, 0, $length, 'UTF-8'); $result .= '...'; } else { $result = $excerpt; } } else { $content = trim(strip_shortcodes($content)); if (strlen($content) > strlen(strip_shortcodes($content))) { $length = $length == 0 ? strlen($content) : $length; $content = de_excerpt('', $content, $length); } $content = strip_tags($content); $length = $length == 0 ? strlen($content) : $length; if (strlen($content) > $length) { $result = mb_substr($content, 0, $length, 'UTF-8'); $result .= '...'; } else { $result = $content; } } return $result; }
function truncate_content($limit, $echo = true, $paragraphs = true, $customfield = 0) { global $post; $output = ''; if ($customfield !== 0) { $output = get_post_meta($post->ID, $customfield, true); } if ($output == '') { $content = get_the_content(); $content = strip_shortcodes(strip_tags($content)); $len = strlen($content); if ($len > $limit) { $output = substr($content, 0, $limit); $output .= '...'; } else { $output = $content; } } if ($paragraphs == true) { $output = '<p>' . $output . '</p>'; } if ($echo) { echo $output; } else { return $output; } }
private function get_post() { if (isset($this->options['text_limit']) && !empty($this->options['text_limit'])) { $limit = $this->options['text_limit']; } else { $limit = 100; } $start_date = date('F jS, Y', strtotime($this->options['start_date'])); $getPost = new WP_Query(array('cat' => implode(',', $this->options['categories']), 'date_query' => array(array('after' => $start_date)), 'orderby' => 'date', 'order' => 'ASC', 'meta_query' => array('relation' => 'OR', array('key' => 'aus_telegram_sent', 'compare' => 'NOT EXISTS', 'value' => '')), 'posts_per_page' => 1)); if (isset($getPost->posts[0])) { $getPost = $getPost->posts[0]; $text = $getPost->post_content; $text = strip_shortcodes($text); $text = preg_replace('/[\\r\\n]+/', "", $text); $text = preg_replace('/\\s+/', ' ', $text); $text = trim($text); $text = strip_tags($text); $text = $this->limit($text, $limit); $cat_ids = wp_get_post_categories($getPost->ID); if (!empty($cat_ids)) { $category = get_category($cat_ids[0])->name; } else { $category = ''; } $post = array('id' => $getPost->ID, 'title' => $getPost->post_title, 'url' => $getPost->guid, 'date' => date('d.m.Y', strtotime($getPost->post_date)), 'category' => $category, 'text' => $text); wp_reset_query(); return $post; } else { return false; } }
/** * Function to create an excerpt for the post. * * @since 1.6 * * @param int $id Post ID * @param int|string $excerpt_length Length of the excerpt in words * @return string Excerpt */ function crp_excerpt($id, $excerpt_length = 0, $use_excerpt = true) { $content = $excerpt = ''; if ($use_excerpt) { $content = get_post($id)->post_excerpt; } if ('' == $content) { $content = get_post($id)->post_content; } $output = strip_tags(strip_shortcodes($content)); if ($excerpt_length > 0) { $output = wp_trim_words($output, $excerpt_length); } /** * Filters excerpt generated by CRP. * * @since 1.9 * * @param array $output Formatted excerpt * @param int $id Post ID * @param int $excerpt_length Length of the excerpt * @param boolean $use_excerpt Use the excerpt? */ return apply_filters('crp_excerpt', $output, $id, $excerpt_length, $use_excerpt); }
function ubermenu_recent_posts($atts) { global $uberMenu; extract(shortcode_atts(array('num' => 3, 'img' => 'on', 'img_size' => 'inherit', 'img_width' => 45, 'img_height' => 45, 'excerpt' => 'off', 'category' => '', 'default_img' => false, 'offset' => 0), $atts)); $args = array('numberposts' => $num, 'offset' => $offset, 'suppress_filters' => false); if (!empty($category)) { if (is_numeric($category)) { $args['category'] = $category; } else { $args['category_name'] = $category; } } $posts = get_posts($args); $class = 'ubermenu-postlist'; if ($img == 'on') { $class .= ' ubermenu-postlist-w-img'; } $html = '<ul class="' . $class . '">'; foreach ($posts as $post) { $ex = $post->post_excerpt; if ($ex == '' && function_exists('wp_trim_words')) { //wp_trim_words is a WP3.3 function $ex = $post->post_content; $ex = strip_shortcodes($ex); $ex = str_replace(']]>', ']]>', $ex); $excerpt_length = apply_filters('excerpt_length', 55); $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]'); $ex = wp_trim_words($ex, $excerpt_length, $excerpt_more); } //$ex = apply_filters('get_the_excerpt', $post->post_excerpt); $post_url = get_permalink($post->ID); $image = ''; $w = $img_width; $h = $img_height; $content_styles = array(); //if($img == 'on') $image = $uberMenu->getPostImage($post->ID, $w, $h, $default_img); if ($img == 'on') { $img_data = ubermenu_get_image(false, $post->ID, true, array('img_w' => $w, 'img_h' => $h, 'img_size' => $img_size, 'default_img' => $default_img)); if (isset($img_data['img'])) { $image = $img_data['img']; $content_styles['padding-left'] = $img_data['w'] + 10 . 'px'; } } $_content_styles = ''; if (!empty($content_styles)) { $_content_styles = 'style="'; foreach ($content_styles as $prop => $val) { $_content_styles .= $prop . ':' . $val . ';'; } $_content_styles .= '"'; } $html .= '<li class="ubermenu-postlist-item">' . $image . '<div class="ubermenu-postlist-title" ' . $_content_styles . '><a href="' . $post_url . '">' . $post->post_title . '</a></div>'; if ($excerpt == 'on') { $html .= '<div class="ubermenu-postlist-content" ' . $_content_styles . '>' . $ex . '</div>'; } $html .= '</li>'; } $html .= '</ul>'; return $html; }
/** * Get an array of words from a string. Parses out HTML tags and shortcodes, removes punctuation, * removes line breaks, removes whitespace, lowercase all words, removes stop words, and removes * words that are less than 3 characters. * * @access private * * @param string $text String of text to parse * * @uses strip_shortcodes() * @uses apply_filters() * * @return array Sanitized words */ private function get_sanitized_word_array($text) { // Strip html tags and shortcodes $text = strip_tags($text); $text = strip_shortcodes($text); // Remove anything that's not a letter or number $text = preg_replace('/[^a-zA-Z 0-9]+/', ' ', $text); // Remove line breaks $text = str_replace("\n", '', $text); $text = str_replace("\r", '', $text); // Replace multiple spaces with a single space $text = preg_replace('!\\s+!', ' ', $text); // Create an array of words $words = explode(' ', $text); // Lowercase and trim the words $words = array_map('strtolower', $words); $words = array_map('trim', $words); // Define our stop words $stopwords = apply_filters('mlt_stop_words', array('a', 'just', 'nbsp', 'about', 'above', 'above', 'across', 'after', 'afterwards', 'again', 'against', 'all', 'almost', 'alone', 'along', 'already', 'also', 'although', 'always', 'am', 'among', 'amongst', 'amoungst', 'amount', 'an', 'and', 'another', 'any', 'anyhow', 'anyone', 'anything', 'anyway', 'anywhere', 'are', 'around', 'as', 'at', 'back', 'be', 'became', 'because', 'become', 'becomes', 'becoming', 'been', 'before', 'beforehand', 'behind', 'being', 'below', 'beside', 'besides', 'between', 'beyond', 'bill', 'both', 'bottom', 'but', 'by', 'call', 'can', 'cannot', 'cant', 'co', 'con', 'could', 'couldnt', 'cry', 'de', 'describe', 'detail', 'do', 'done', 'down', 'due', 'during', 'each', 'eg', 'eight', 'either', 'eleven', 'else', 'elsewhere', 'empty', 'enough', 'etc', 'even', 'ever', 'every', 'everyone', 'everything', 'everywhere', 'except', 'few', 'fifteen', 'fify', 'fill', 'find', 'fire', 'first', 'five', 'for', 'former', 'formerly', 'forty', 'found', 'four', 'from', 'front', 'full', 'further', 'get', 'give', 'go', 'had', 'has', 'hasnt', 'have', 'he', 'hence', 'her', 'here', 'hereafter', 'hereby', 'herein', 'hereupon', 'hers', 'herself', 'him', 'himself', 'his', 'how', 'however', 'hundred', 'ie', 'if', 'in', 'inc', 'indeed', 'interest', 'into', 'is', 'it', 'its', 'itself', 'keep', 'last', 'latter', 'latterly', 'least', 'less', 'ltd', 'made', 'many', 'may', 'me', 'meanwhile', 'might', 'mill', 'mine', 'more', 'moreover', 'most', 'mostly', 'move', 'much', 'must', 'my', 'myself', 'name', 'namely', 'neither', 'never', 'nevertheless', 'next', 'nine', 'no', 'nobody', 'none', 'noone', 'nor', 'not', 'nothing', 'now', 'nowhere', 'of', 'off', 'often', 'on', 'once', 'one', 'only', 'onto', 'or', 'other', 'others', 'otherwise', 'our', 'ours', 'ourselves', 'out', 'over', 'own', 'part', 'per', 'perhaps', 'please', 'put', 'rather', 're', 'same', 'see', 'seem', 'seemed', 'seeming', 'seems', 'serious', 'several', 'she', 'should', 'show', 'side', 'since', 'sincere', 'six', 'sixty', 'so', 'some', 'somehow', 'someone', 'something', 'sometime', 'sometimes', 'somewhere', 'still', 'such', 'system', 'take', 'ten', 'than', 'that', 'the', 'their', 'them', 'themselves', 'then', 'thence', 'there', 'thereafter', 'thereby', 'therefore', 'therein', 'thereupon', 'these', 'they', 'thickv', 'thin', 'third', 'this', 'those', 'though', 'three', 'through', 'throughout', 'thru', 'thus', 'to', 'together', 'too', 'top', 'toward', 'towards', 'twelve', 'twenty', 'two', 'un', 'under', 'until', 'up', 'upon', 'us', 'very', 'via', 'was', 'we', 'well', 'were', 'what', 'whatever', 'when', 'whence', 'whenever', 'where', 'whereafter', 'whereas', 'whereby', 'wherein', 'whereupon', 'wherever', 'whether', 'which', 'while', 'whither', 'who', 'whoever', 'whole', 'whom', 'whose', 'why', 'will', 'with', 'within', 'without', 'would', 'yet', 'you', 'your', 'yours', 'yourself', 'yourselves', 'the')); // Remove stop words from our words array $words = preg_replace('/\\b(' . implode('|', $stopwords) . ')\\b/', '', $words); // Remove words that are less than 3 characters $words = array_filter($words, function ($word) { return strlen($word) > 2; }); // Return the results return $words; }
/** * Generates an excerpt from the given content string. * * Adapted from WordPress's `wp_trim_excerpt' function that is not useful * for applying to custom content. * * @param string $text The content to trim. * * @return string The excerpt. */ public function trim_excerpt(Ai1ec_Event $event, $length = 35, $more = '[...]') { global $post; $original_post = $post; $post = $event->get('post'); $raw_excerpt = $event->get('post')->post_content; if (!isset($raw_excerpt[0])) { $raw_excerpt = ' '; } $text = preg_replace('#<\\s*script[^>]*>.+<\\s*/\\s*script\\s*>#x', '', apply_filters('the_excerpt', $raw_excerpt)); $text = strip_shortcodes($text); $text = str_replace(']]>', ']]>', $text); $text = strip_tags($text); $excerpt_length = apply_filters('excerpt_length', $length); $excerpt_more = apply_filters('excerpt_more', $more); $words = preg_split('/\\s+/', $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY); if (count($words) > $excerpt_length) { array_pop($words); $text = implode(' ', $words); $text = $text . $excerpt_more; } else { $text = implode(' ', $words); } $post = $original_post; return apply_filters('wp_trim_excerpt', $text, $raw_excerpt); }
function remove_shortcode_from_archive($content) { if (!is_singular()) { $content = strip_shortcodes($content); } return $content; }
private function estimate_word_count() { global $asian_languages; $data = $this->data; $words = 0; if (isset($data->language_code)) { $lang_code = $data->language_code; if (isset($data->title)) { if ($asian_languages && in_array($lang_code, $asian_languages)) { $words += strlen(strip_tags($data->title)) / ICL_ASIAN_LANGUAGE_CHAR_SIZE; } else { $words += count(preg_split('/[\\s\\/]+/', $data->title, 0, PREG_SPLIT_NO_EMPTY)); } } $post_obj = get_post($data->ID); $post_content = $post_obj ? $post_obj->post_content : ""; $post_content = strip_tags($post_content); if ($this->exclude_shortcodes_in_words_count()) { $post_content = strip_shortcodes($post_content); } if ($asian_languages && in_array($lang_code, $asian_languages)) { $words += strlen($post_content) / ICL_ASIAN_LANGUAGE_CHAR_SIZE; } else { $words += count(preg_split('/[\\s\\/]+/', $post_content, 0, PREG_SPLIT_NO_EMPTY)); } } return $words; }
private function truncate_string($string, $min) { $string = strip_shortcodes($string); $text = trim(strip_tags($string)); if (strlen($text) > $min) { $blank = strpos($text, ' '); if ($blank) { # limit plus last word $extra = strpos(substr($text, $min), ' '); $max = $min + $extra; $r = substr($text, 0, $max); if (strlen($text) >= $max) { $r = trim($r, '.') . '...'; } } else { # if there are no spaces $r = substr($text, 0, $min) . '...'; } } else { # if original length is lower than limit $r = $text; } $r = trim(preg_replace('/\\s\\s+/', ' ', $r)); return $r; }
/** * Customize excerpt length and style. * * @param string The raw post content. * @return string */ function red_wp_trim_excerpt($text) { $raw_excerpt = $text; if ('' == $text) { // retrieve the post content $text = get_the_content(''); // delete all shortcode tags from the content $text = strip_shortcodes($text); $text = apply_filters('the_content', $text); $text = str_replace(']]>', ']]>', $text); // indicate allowable tags $allowed_tags = '<p>,<a>,<em>,<strong>,<blockquote>,<cite>'; $text = strip_tags($text, $allowed_tags); // change to desired word count $excerpt_word_count = 50; $excerpt_length = apply_filters('excerpt_length', $excerpt_word_count); // create a custom "more" link $excerpt_end = '<span>[...]</span><p><a href="' . get_permalink() . '" class="read-more">Read more →</a></p>'; // modify excerpt ending $excerpt_more = apply_filters('excerpt_more', ' ' . $excerpt_end); // add the elipsis and link to the end if the word count is longer than the excerpt $words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY); if (count($words) > $excerpt_length) { array_pop($words); $text = implode(' ', $words); $text = $text . $excerpt_more; } else { $text = implode(' ', $words); } } return apply_filters('wp_trim_excerpt', $text, $raw_excerpt); }
function get_upcoming_events() { global $wp_theatre; $args = array('upcoming' => true); $events = $wp_theatre->events->get($args); $items = ''; foreach ($events as $event) { $item = ''; $item .= '<item>'; $item .= '<title>' . $event->production()->title() . '</title>'; $item .= '<link>' . get_permalink($event->production()->ID) . '</link>'; $item .= '<description><![CDATA[' . $event->production()->summary() . ']]></description>'; $item .= '<content:encoded><![CDATA[' . strip_shortcodes($event->production()->post()->post_content) . ']]></content:encoded>'; $item .= '</item>'; $items .= $item; } $feed = ''; $feed .= '<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">'; $feed .= '<channel>'; $feed .= '<title>' . get_bloginfo_rss('name') . ' ' . __('Upcoming events', 'wp_theatre') . '</title>'; $feed .= '<link>' . get_bloginfo_rss('url') . '</link>'; $feed .= '<description>' . get_bloginfo_rss("description") . '</description>'; $feed .= $items; $feed .= '</channel>'; $feed .= '</rss>'; return $feed; }
public function ya_trim_words($text, $num_words = 30, $more = null) { $text = strip_shortcodes($text); $text = apply_filters('the_content', $text); $text = str_replace(']]>', ']]>', $text); return wp_trim_words($text, $num_words, $more); }
function custom_wp_trim_excerpt($text) { $raw_excerpt = $text; if ('' == $text) { //Retrieve the post content. $text = get_the_content(''); $text = strip_shortcodes($text); $text = apply_filters('the_content', $text); $text = str_replace(']]>', ']]>', $text); // the code below sets the excerpt length to 55 words. You can adjust this number for your own blog. $excerpt_length = apply_filters('excerpt_length', 55); // the code below sets what appears at the end of the excerpt, in this case ... $excerpt_more = apply_filters('excerpt_more', ' ' . '...'); $words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY); if (count($words) > $excerpt_length) { array_pop($words); $text = implode(' ', $words); $text = force_balance_tags($text); $text = $text . $excerpt_more; } else { $text = implode(' ', $words); } } return apply_filters('wp_trim_excerpt', $text, $raw_excerpt); }
/** * * @param string $string * @param int $word_limit * @param string $ending * @return string */ function clean_text($string, $word_limit = 0, $ending = ' ...') { //remove wp shortcodes $string = \strip_shortcodes($string); //adds a space before every tag open so we don't get heading/paragraphs glued together when we strip tags $string = str_replace('<', ' <', $string); //strip tags $string = strip_tags($string); //convert space entities to normal spaces to help out some users $string = str_replace(' ', ' ', $string); //convert to html entities $string = htmlspecialchars($string); //convert space entities to regular spaces so we can remove double spaces - all other hmtl entities should be fine $string = str_replace(' ', ' ', $string); //removes double spaces, tabs or line breaks, and trim the result $string = trim(mb_ereg_replace('\\s+', ' ', $string)); //limit if ($word_limit) { $words = explode(' ', $string); if (count($words) > $word_limit) { array_splice($words, $word_limit); $string = implode(' ', $words) . $ending; } } return $string; }
public function trim_excerpt($text) { $raw_excerpt = $text; if ('' == $text) { $text = get_the_content(''); $text = strip_shortcodes($text); $text = apply_filters('the_content', $text); $text = str_replace(']]>', ']]>', $text); $text = strip_tags($text); $excerpt_length = apply_filters('character_count_excerpt_length', $this->get_excerpt_characters()); if (strlen($text) > $excerpt_length) { $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]'); $text = substr($text, 0, $excerpt_length + 1); $words = preg_split("/[\n\r\t ]+/", $text, -1, PREG_SPLIT_NO_EMPTY); // if the last character is not a white space, we remove the cut off last word preg_match("/[\n\r\t ]+/", $text, $lastchar, 0, $excerpt_length); if (empty($lastchar)) { array_pop($words); } $text = implode(' ', $words); $text = $text . $excerpt_more; } } return apply_filters('wp_trim_excerpt', $text, $raw_excerpt); }