2016-03-02 74 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

很高兴我可以帮助:) –

相关问题