<a href="/quote/tag/<?php echo get_post_meta($post->ID, 'user_submit_customauthor2', true); ?>">My Link></a>
我得到了这段代码,将echos'user_submit_customauthor2'放入网址。问题是它用%20替换了空格,我希望用连字符' - '替换它。
我搜索了一段代码
$string = str_replace(" ", "-", $string);
但我找不到任何告诉我应该如何插入它的东西。我是否将其作为功能并调用它?有没有办法将其与链接内联?
答案 0 :(得分:2)
<?php
$string = get_post_meta($post->ID, 'user_submit_customauthor2', true);
string = str_replace(" ", "-", $string);
echo '<a href="/quote/tag/'.$string.'">My Link></a>';
答案 1 :(得分:0)
如果你愿意,你可以这样做:
<a href="/quote/tag/<?php echo str_replace(" ", "-", get_post_meta($post->ID, 'user_submit_customauthor2', true)); ?>">My Link></a>