Reputation: 23
The following code give me a link title with "%20" instead of spaces and adds "http://" before the title.
"user_url" is the link url.
"tagline" is the title text (e.g. "Lorem ipsum dolor sit amet, consectetur adipiscing elit...")
The output is: "http://Lorem&20ipsum&20dolor&20sit&20amet&20consectetur&20adipiscing&20elit"
What I want is just the clean text.
Any advice?
Here's the code:
<?php if( !empty( $current_author_profile->user_url ) ) {?>
<li><i class="fa fa-link"></i><a href="<?php echo esc_url( $current_author_profile->user_url );?>" target="_blank" title="<?php echo esc_url( $current_author_profile->tagline );?>"><?php echo docdirect_parse_url( $current_author_profile->user_url);?></a></li>
<?php }?>
Thanks! :)
Upvotes: 0
Views: 60
Reputation: 96
It's better to use htmlentities()
since the title needs to be escaped between double quotes, because if the text happens to contain double quotes itself it will break the title or even mess up the functionality of the html tag. See http://php.net/manual/en/function.htmlentities.php:
htmlentities — Convert all applicable characters to HTML entities
title="<?php echo htmlentities($current_author_profile->tagline, ENT_QUOTES | ENT_HTML5);?>"
I prefer to quote both double and single quotes with ENT_QUOTES
in the second parameter flags
of the htmlentities()
-function. Please check the documentation link for more details of available flags, encoding parameter etc.
Upvotes: 2
Reputation: 21564
That's because you are URL-escaping your title:
title="<?php echo $current_author_profile->tagline;?>"
should work.
Upvotes: 2