I need to show the title of the current post in a particular way.
Post titles are like:
Balubano 24
Balubano 25
Balubano 26
etc...
I want to only show:
Bal. 24
Bal. 25
Bal. 26
In summary, just replace the characters ubano
with a dot
. Balubano 176 becomes Bal. 176
Note: I don't want to edit the database, just change how it appears in the template when I call it.
How can I edit the following in order to achieve my goal?
<?php echo get_the_title(); ?>
If I understand correctly, you are trying to add abbreviations in the post title.
If the abbreviation list is known, you can use the str_replace function as such:
You can alter the way titles are displayed by using a filter.
The function you're using,
get_the_title()
, is run through thethe_title
filter.To modify the output add the following code to your functions.php file:
You can also shorten
echo get_the_title()
to justthe_title()
.