I’m trying to use a function that adds a “span” around the first word of every post title in a WordPress site, and found this extremely similar question. The function in the second answer works fine when there’s a link inside the H2 element.
But In my site, I’m not using the post title as a link, so the found solution doesn’t work. I’ve tried to come up with a new preg-replace pattern, as to skip the detection of the link part, but haven’t been able to get it.
Basically, I want this:
<h2><?php the_title(); ?></h2> or <h2>Converted post title</h2>
… to become this:
<h2><span>Converted</span> post title</h2>
Best way to do that using woodpress hooks and filter. so that you can use the_title() function without additional code.
put this code into functions.php in your theme folder. that’s all.
You can use something like this:
I suggest you do that in javascript so you could lessen the processing/cpu use of the server. You would still have the same result.
https://gist.github.com/2440296#file_h2_span1stw_2.htm
*Previous code version..
https://gist.github.com/2440296#file_h2_span1stw.htm
http://jsbin.com/uguhel/edit#html,live