I have a child theme in wordpress that is based on twentyten.
Some of my authors have hardcoded URLs in their post titles and I want to remove those URLs.
I put the following code in my functions.php
file in the child theme, but it has no effect on the display of the post title:
add_filter( âthe_titleâ, âib_strip_tags_from_titlesâ );
function ib_strip_tags_from_titles( $title ) {
$title = strip_tags( $title );
return $title;
}
Any suggestions?
strip_tags()
only removes HTML tags – in your case it will change the title fromSome Text <a href="http://someurl.com">LINK</a> Other Text
to
Some Text LINK Other Text
If I understand you correctly, this is what you want:
going with the above example it will output
Some Text Other Text
Note that given that you tried to accomplish the task with
strip_tags()
, I am assuming the “harcoded URLs”, as you described them, are enclosed in<a [...] ></a>
tags. If that’s not the case you would need a regular expression that matches URLs. That is much more tricky, depending on whether the URLs your authors use are internationalized / have different domains, are not all just http:// prefaced and so on.I vouch for the above to work if they are enclosed in tags, if not, this regex will catch most URLs, but comes without my guarantee to work in every case:
(([A-Za-z]{3,9})://)?([-;:&=+$,w]+@{1})?(([-A-Za-z0-9]+.)+[A-Za-z]{2,3})(:d+)?((/[-+~%/.w]+)?/?([&?][-+=&;%@.w]+)?(#[w]+)?)?
You’d have put that between the ‘/ and /’ in the above function.