Support » Fixing WordPress » Links are not clickable in posts page

Viewing 3 replies - 1 through 3 (of 3 total)
  • in your index.php it probably uses the_excerpt rather that the_content

    the_excerpt truncates posts, but also removes links. You can swap it for the_content of you like, but that will also show full posts

    This might be overkill, but I created a function that I can pass in a variable length string and chop it, or just get the post content and chop it.

    function new_improved_trim_excerpt($text = '', $word_length = 55) {
    		global $post;
    
    	  	$tag = '<a href="%s">Read more %s</a>';
    	  	$link = get_permalink($post->ID);
    		$text = (empty($text)) ? get_the_content() : $text;
    		$text = strip_shortcodes( $text );
    		$text = apply_filters('the_content', $text);
    		$text = str_replace(']]>', ']]>', $text);
    		$text = strip_tags($text, '<strong><br><br />');
    		$excerpt_length = apply_filters('excerpt_length', $word_length);
    		$excerpt_more = apply_filters('excerpt_more', ' ' . '<strong>&hellip;</strong><div class="el-post-meta-bottom"><a class="necor" href="'.$link.'"><img src="/images/layout/btn_more.png" width="43" height="12" alt="Wanna See More???" /></a></div>');
    		$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 $text;
    	}
    
    	remove_filter('get_the_excerpt', 'wp_trim_excerpt');
    	add_filter('get_the_excerpt', 'new_improved_trim_excerpt');

    Another one from the same project I used on titles, like link lists for posts with long titles.

    Both of these came from a blog that had been custom and were thousands of posts. And the excerpt didn’t exist and the need to format single line titles. As well as some str replacing because there were numerous butchered incorrect encoding chars in the old posts (and breaks and new lines.. etc)

    function shorten_copy($str, $len, $replace='', $cut=false){
    		// those special chars were fucking this up:
    		$from = array('“', '”', '‘', '’','\xE2\x80\x9C', '\xE2\x80\x9D',
    			'\xE2\x80\x9E', '\xE2\x80\x9F', '%e2%80%99', '%e2%80%9c', '%e2%80%9d');
    		$to =   array('"', '"', "'", "'", '"', '"', '"', '"', "'", '"', '"');
    		$str = str_replace($from, $to, $str);
    
       		if(strlen($str)<=$len){
       			return $str.$replace;
       		}else{
       			$result = ($cut ? substr($str, 0, $len) : substr($str, 0, strrpos(substr($str, 0, $len), ' '))).$replace;
    
       			// just in case we end up with a wacky situation where the result === the replacement string. It happens on wordpress because of special chars.
       			// E.g. you can end up with strings like this: %e2%80%99Somethingreallylong%e2%80%9d which can end up being one string and turns into '...', i.e. the replacement string.
        		return ($result == $replace) ? substr($str, 0, $len) : $result;
       		}
    	}
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Links are not clickable in posts page’ is closed to new replies.