2014-10-17 29 views
0

我怎樣才能擺脫爲http://此:條HTTP:從the_author_url //()

<a href="<?php the_author_url(); ?>"><?php the_author_url()); ?></a> 

我已經試過這樣:

<a href="<?php the_author_url(); ?>"> 
    <?php $url = the_author_url(); 
    $url = substr($url,0,6); 
    echo $url; ?> 
</a> 

但無效果...

+0

如何嘗試'str_replace()'? 'str_replace(「http://」,「」,the_author_url());' – Albzi 2014-10-17 11:26:40

+0

請注意,該函數已被棄用。您應該使用['the_author_meta('user_url')'](http://codex.wordpress.org/Function_Reference/the_author_url)。 – 2014-10-17 11:33:40

回答

1

the_author_meta()將無法​​正常工作,因爲該功能echo上課的結果。相反,您需要使用get_the_author_meta('user_url'),即return的URL。

<a href="<?php the_author_meta('user_url'); ?>"> 
    <?php echo str_replace('http://', '', get_the_author_meta('user_url')); ?> 
</a> 

注意,這並不佔https的URL(你可以使用正則表達式替換功能,如果需要的話)。

1

好吧,你差不多了。嘗試使用這樣的:

<?php 
function the_author_url(){ 
    return 'http://www.google.com'; 
} 
$url = substr(the_author_url(),7); 

?> 
<a href="<?=the_author_url()?>"><?=$url?></a> 

或者是這樣的:

<?php 
function the_author_url(){ 
    return 'http://www.google.com'; 
} 
$url = str_replace('http://','',the_author_url()); 

?> 
<a href="<?=the_author_url()?>"><?=$url?></a> 

演示:https://eval.in/207127

+0

<?php \t $ url = str_replace(「http://」,「」,the_author_meta('user_url')); \t echo $ url; ?> – Geoff 2014-10-18 08:23:44

+0

感謝您的幫助,它對我來說似乎完全沒問題 - 但上述不適合我 - 任何想法我做錯了什麼? : -/ – Geoff 2014-10-18 08:25:17

+0

什麼返回the_author_meta('user_url')?像http://example.com/? – ThatMSG 2014-10-22 15:58:58