Support » How-To and Troubleshooting » How to shorten content in Custom Fields

How to shorten content in Custom Fields

  • Hey,

    im using custom fields to add a url for a demo link on my posts (demo: Knowtebook.com, but sometimes the url is too long and I would like to shorten them like http://www.trendsand…dkdjdh.html

    I have tried it with a function in functions.php:

    // Links bzw. string kürzen und zurückgeben
    function ShortenText($text)
    	// Change to the number of characters you want to display
    	$chars_limit = 55;
    	$chars_text = strlen($text);
    	$text = $text." ";
    	$text = substr($text,0,$chars_limit);
    	$text = substr($text,0,strrpos($text,' '));
    	// Wenn Text mehr Zeichen als Zeichenlimit hat, füge ... hinzu
    	if ($chars_text > $chars_limit)
    		$text = $text."...";
    	return $text; 

    and called in in single.php with:

    Link: <a href="<?php $link = get_post_meta($post->ID, "post-url", $single = true); echo get_post_meta($post->ID, "post-url", $single = true); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>" target="_blank">
    									<?php the_title(); ?> - <?php echo ShortenText($link); ?>

    It doesnt work. Any idea or plugins?

  • The topic ‘How to shorten content in Custom Fields’ is closed to new replies.