Hello guys, Can someone please help me? I need to limit character on title using the variable $post_title, how can I do it? This is my code: <a target="_blank" href="<?php echo get_post_meta($ID,'mr_freeGalleryUrl',true); ?>" rel="nofollow"><?php echo $post_title; ?></a> PHP: Waiting for your precious help, thanks Kind regards
just change the <?php echo $post_title; ?> PHP: to <?php echo substr($post_title,0,20).'…'; ?> PHP: which will output something like this: <?php $post_title = 'This is a post-title with more than 20 characters which will end up like'; echo substr($post_title,0,20).'…'; ?> //output: This is a post-title⦠PHP: If you don't want the horisontal ellipsis when the post title is below the amount set, you can just do something like this: <?php $length = 20; $post_title = 'This is a post'; echo substr($post_title,0,$length).((strlen($post_title) > $length) ? '…' : ''); //output: This is a post $post_title = 'This is a post-title with more than 20 characters which will end up like'; echo substr($post_title,0,$length).((strlen($post_title) > $length) ? '…' : ''); //output: This is a post-title... ?> PHP: