I want to replace first word in title to have <span></span>
inside.
Example for WordPress title
<h2 class="entry-title"><a href="#">Welcome to WordPress</a></h2>
I want to be like this
<h2 class="entry-title"><a href="#"><span>Welcome</span> to WordPress</a></h2>
the function
function span_on_title($span) {
return preg_replace('', '', $span, 1);
}
add_filter('the_title','span_on_title');
May i know what to put on the preg_replace
Add this to your functions.php file in your theme:
The output on the frontend for instance, will look like this:
But it won’t be affected on the backend while viewing the posts table.
And then you can style it in your style.css like this for instance:
EDIT: added if else statement to adjust formatting for frontend theme only without adjusting backend theme. Seems to work just fine. If there is a better way, I’d love to hear it, Thanks!