Reputation: 4008
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
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
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