I’m trying to substring the title which it is called via the method the_title() .
Here are 2 things I did to do it but they both failed.
first try: <?php echo substr(the_title(),1,15) ?>
second try: <?php $new_title = the_title() ; echo substr($new_title, 1,15) ?>
They both didn’t work. when I used the second try I still get the full title.
Note: I’m trying to implement this on a WordPress script, also it’s for my php practice.
Thanks in Advance.
The function
the_title()does not return the title as string but outputs it by default.Use
the_title('','', 1)which makes it return the title or the alternative functionget_the_title()instead.