<a href="/quote/tag/<?php echo get_post_meta($post->ID, 'user_submit_customauthor2', true); ?>">My Link></a>
I got this piece of code that echos 'user_submit_customauthor2' into an url. The problem is that it replaces space with %20 and I'd like it to replace it with a hyphen '-' instead.
I have searched an found this piece of code
$string = str_replace(" ", "-", $string);
But I couldn't find anything that tells me how I'm supposed to insert it. Do I make it a function and call it? Is there a way to place it inline with the link?
<?php
$string = get_post_meta($post->ID, 'user_submit_customauthor2', true);
string = str_replace(" ", "-", $string);
echo '<a href="/quote/tag/'.$string.'">My Link></a>';
如果需要,您可以这样做:
<a href="/quote/tag/<?php echo str_replace(" ", "-", get_post_meta($post->ID, 'user_submit_customauthor2', true)); ?>">My Link></a>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.