From 714a39c700e6965a065c3055f215e137fc64f486 Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Thu, 28 Jan 2016 16:04:14 -0500 Subject: [PATCH] restriction home page excerpts --- functions.php | 11 +++++++++++ js/app.js | 17 +---------------- js/custom/pageSetup.js | 17 +---------------- 3 files changed, 13 insertions(+), 32 deletions(-) diff --git a/functions.php b/functions.php index 98d1924..7b48a1b 100644 --- a/functions.php +++ b/functions.php @@ -167,4 +167,15 @@ function glm_has_shortcode($shortcode) $page = get_post( $post->ID ); return has_shortcode( $page->post_content, $shortcode ); } +function ca_only_add_more_when_required( $default, $text, $options ) { + $text = strip_tags( $text ); + if ( 'words' === $options['length_type'] ) { + $excerpt_length = str_word_count( $text ); + } else { + $excerpt_length = strlen( $text ); + } + if ( $excerpt_length > $options['length'] ) return $default; + return true; +} +add_filter( 'advanced_excerpt_disable_add_more', 'ca_only_add_more_when_required', 10, 3 ); ?> diff --git a/js/app.js b/js/app.js index f3bd5ed..b7df57b 100644 --- a/js/app.js +++ b/js/app.js @@ -110,22 +110,7 @@ $(document).ready(function () { $(this).parent("li").addClass("current"); } }); - - // remove link from posts with less than 225 characters - for (var i = 0; i < $('div[class*="excerpt"]').length; i++){ - var chars= $(".excerpt" + i).text(); - - if(chars.length < 225){ - chars = chars.substr(0,chars.length - 2); - - // disable link if excerpt is < 225 characters - $(".excerpt" + i).parent().find("a").replaceWith(function(){ - return $("", {html: $(this).html()}); - }); - $('.excerpt' + i).text(chars); - } - } - $(".title-posts").find("span").addClass("excerptTitle"); + /* get number of elements in DOM console.log($("*").length); var pageBytes = $('html').html().length; diff --git a/js/custom/pageSetup.js b/js/custom/pageSetup.js index 3ce0ccb..8989f93 100644 --- a/js/custom/pageSetup.js +++ b/js/custom/pageSetup.js @@ -101,22 +101,7 @@ $(document).ready(function () { $(this).parent("li").addClass("current"); } }); - - // remove link from posts with less than 225 characters - for (var i = 0; i < $('div[class*="excerpt"]').length; i++){ - var chars= $(".excerpt" + i).text(); - - if(chars.length < 225){ - chars = chars.substr(0,chars.length - 2); - - // disable link if excerpt is < 225 characters - $(".excerpt" + i).parent().find("a").replaceWith(function(){ - return $("", {html: $(this).html()}); - }); - $('.excerpt' + i).text(chars); - } - } - $(".title-posts").find("span").addClass("excerptTitle"); + /* get number of elements in DOM console.log($("*").length); var pageBytes = $('html').html().length; -- 2.17.1