Get WordPress Title Without something

Mauricio Villa asked
php wordpress

I dont know If I can explain myself properly but I want to get the title but without something, for example:

The title is: “Recipie: Orange Juice” and I get it with this

<?php the_title(); ?>

And I want to get just “Orange Juice” Is it possible?


The proper way to do this:

// Get the title.
$title = get_the_title();

// Replace leading prefix and colon if one exists.
$title = preg_replace('/^[^:]+:s*/', '', $title);

// Output the title.
echo $title;
Share This
Posted in: