Display wordpress post titles with a custom length
Display wordpress post titles with a custom length
If you want to display only the first X characters of your wordpress post title, I display here some hack for that.
The first thing to do is to create the function. Open your functions.php file and paste this code:
function ODD_title($char) {
$title = get_the_title($post->ID);
$title = substr($title,0,$char);
echo $title;
}
Now, you use the function on your wordpress theme files. Just pass how many characters you want to display as a parameter. In the following example, only the first 30 chars of the title will be displayed:
ODD_title(20);
So with the following code you can display wordpress post titles with a custom length
Display wordpress post titles with a custom length
If you want to display only the first X characters of your wordpress post title, I display here some hack for that.
The first thing to do is to create the function. Open your functions.php file and paste this code:
function ODD_title($char) {
$title = get_the_title($post->ID);
$title = substr($title,0,$char);
echo $title;
}
Now, you use the function on your wordpress theme files. Just pass how many characters you want to display as a parameter. In the following example, only the first 30 chars of the title will be displayed:
ODD_title(20);
So with the following code you can display wordpress post titles with a custom length
No comments:
Post a Comment