如何在共享社交按钮标题之前添加文本?

时间:2015-11-29 15:11:40

标签: php wordpress

我想在标题前添加一些文字。例如,"新 - the_title()"

$crunchifyTitle = str_replace( ' ', '%20', get_the_title());

所以它会显示出来," New - Planet tee"

add_action( 'woocommerce_share', 'crunchify_social_sharing_buttons');
function crunchify_social_sharing_buttons($content) {
    if(is_singular() || is_home()){

        // Get current page URL 
        $crunchifyURL = get_permalink();

        // Get current page title
        $crunchifyTitle = str_replace( ' ', '%20', get_the_title());

        // Get Post Thumbnail for pinterest
        $crunchifyThumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );

        // Construct sharing URL without using any script
        $twitterURL = 'https://twitter.com/intent/tweet?text='.$crunchifyTitle.'&url='.$crunchifyURL.'&via=Crunchify';
        $facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$crunchifyURL;

        // Based on popular demand added Pinterest too
        $pinterestURL = 'https://pinterest.com/pin/create/button/?url='.$crunchifyURL.'&media='.$crunchifyThumbnail[0].'&description='.$crunchifyTitle;

        // Add sharing button at the end of page/page content
        $content .= '<div class="crunchify-social">';
        $content .= '<h5>SHARE ON</h5> <a class="crunchify-link crunchify-twitter" href="'. $twitterURL .'" target="_blank">Twitter</a>';
        $content .= '<a class="crunchify-link crunchify-facebook" href="'.$facebookURL.'" target="_blank">Facebook</a>';
        $content .= '<a class="crunchify-link crunchify-pinterest" href="'.$pinterestURL.'" target="_blank">Pin It</a>';
        $content .= '</div>';

        echo $content;
    }
}

1 个答案:

答案 0 :(得分:1)

您可以简单地使用连接,以便在标题之前添加一些文字。

$title = 'Title';
$newTitle = 'I am a '. $title;

echo $newTitle; // I am a Title
相关问题