egr103
egr103

Reputation: 4008

How do I show the first letter of the_title in Wordpress?

I have got this code from another post, found here: Get first word in string php the_title WordPress:

<?php $title = get_the_title(); // This must be!, because this is the return - the_title  
would be echo
$title_array = explode(' ', $title);
$first_word = $title_array[0];

echo $first_word;
?>

This should grab the first word but how do I modify it to show the very first letter of the_title in Wordpress?

Upvotes: 0

Views: 3125

Answers (3)

Kiran
Kiran

Reputation: 921

<?php

$title = get_the_title();
echo $title[0];   //print first letter


?>

Another option

<?php

$title = get_the_title();
echo substr($title,0,1);   //takes first character from $title and print //


?>

Upvotes: 0

Ben D
Ben D

Reputation: 14489

echo echo $title[0]; or echo substr($title,0,1);

Upvotes: 3

Halcyon
Halcyon

Reputation: 57703

echo $first_word[0];

or

echo $title[0];

Or perhaps something that makes more sense:

echo substring($title, 0, 1);

Note that you can't do get_the_title()[0] because it's a syntax error.

Upvotes: 3

Related Questions