ThemeShaper Forums » Thematic

[closed]

Shorten Post Title

(3 posts)
  • Started 7 years ago by bogh
  • Latest reply from bogh
  • This topic is resolved
  1. bogh
    Member

    Hi,

    I need to shorten the post titles on home page. Is there an easy way to do it in a Thematic Child Theme?

    I have found this tutorial: http://www.doc4design.com/articles/wordpress-5ways-shorten-titles/
    but I don't know how to use it in Thematic Child Themes.

    Thank you!

    Posted 7 years ago #
  2. either override or filter thematic_postheader_posttitle()

    Posted 7 years ago #
  3. bogh
    Member

    Thank you,

    I have override the thematic_postheader_posttitle() with childtheme_override_postheader_posttitle() and it worked.

    So in case someone needs that I have added the code below.

    //Shorten Post Titles on Home Page
    function ShortenPostTitle($text) { // Function name ShortenText
    	$chars_limit = 50; // Character length
    	$chars_text = strlen($text);
    	$text = $text." ";
    	$text = substr($text,0,$chars_limit);
    	$text = substr($text,0,strrpos($text,' '));
    
    	if ($chars_text > $chars_limit)
    	   { $text = $text."..."; } // Ellipsis
    	   return $text;
    }
    
    function childtheme_override_postheader_posttitle() {
    
    	if (is_single() || is_page(home)) {
    		$posttitle = '<h1 class="entry-title">' . get_the_title() . "</h1>\n";
    	} elseif (is_404()) {
    		$posttitle = '<h1 class="entry-title">' . __('Not Found', 'thematic') . "</h1>\n";
    	} else {
    		$posttitle = '<h2 class="entry-title"><a href="';
    		$posttitle .= apply_filters('the_permalink', get_permalink());
    		$posttitle .= '" title="';
    		$posttitle .= __('Permalink to ', 'thematic') . the_title_attribute('echo=0');
    		$posttitle .= '" rel="bookmark">';
    		$posttitle .= ShortenPostTitle(get_the_title());
    		$posttitle .= "</a></h2>\n";
    	}
    	return apply_filters('childtheme_override_postheader_posttitle',$posttitle);
    }
    Posted 7 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.