显示没有'http'的wp作者元网址

时间:2013-01-07 04:34:03

标签: wordpress

我正在使用WP功能:get_the_author_meta('user_url');

当我向浏览器回复它时,它会自动将“http://”添加到URL。如何避免这种情况,以便我的网址显示与用户设置页面上输入的网址完全相同。

谢谢你的进步。

2 个答案:

答案 0 :(得分:4)

$author_url = get_the_author_meta('user_url'); // e.g. http://www.example.com
$to_remove = array( 'http://', 'https://' );
foreach ( $to_remove as $item ) {
    $author_url = str_replace($item, '', $author_url); // to: www.example.com
}
echo $author_url; // now it will not have the http:// part you wish to avoid.

答案 1 :(得分:1)

str_replace可能是最有效的方法。

$author_url = str_replace(array( 'http://', 'https://' ), '', get_the_author_meta('user_url'));

其他网址修改技巧。

  • 对于更复杂的字符串替换,您可以使用preg_replace
  • 查看
  • 有一个名为http-build-url()的函数,它包含在php_http.dll扩展名中,可能更适合某些用例。
相关问题