2016-03-02 75 views
1

下面是用於顯示的WhatsApp共享圖標的代碼,條件中使用wp_is_mobile如何在URL中包含wordpress標題而在條件標籤中使用echo?

<?php 
    if (wp_is_mobile()) { 
    echo '<a href="whatsapp://send?text=' . the_title() . ', from ' . get_bloginfo('name') . ' ' . wp_get_shortlink() . '" data-action="share/whatsapp/share">'; 
    echo '<i class="fa fa-whatsapp"></i></a>'; 
} 
?> 

the_title是顯示WhatsApp的圖標前屏幕上的標題後,在代替的URL。 如何讓我的文章的標題是URL的一部分,並在文本不顯示在屏幕上

+0

你試過'get_the_title()'嗎? –

+0

是的,正如@dingo_d建議下面 – theKing

回答

1

您需要使用get_the_title(),但除此之外,我會urlencode()整個事情:

<?php 
    if (wp_is_mobile()) { 
     echo '<a href="whatsapp://send?text=' . urlencode(get_the_title() . ', from ' . get_bloginfo('name') . ' ' . wp_get_shortlink()) . '" data-action="share/whatsapp/share">'; 
     echo '<i class="fa fa-whatsapp"></i></a>'; 
    } 
?> 

由於here

(the_title())顯示或返回當前帖子的標題。該標籤只能在The Loop中使用,以獲得帖子外的標題使用get_the_title。如果帖子是受保護的或私人的,則會在標題前加上「受保護:」或「私人:」字樣。

+0

謝謝,它的工作! – theKing

+0

很高興我可以幫助:) –

相關問題