• Menu
  • Skip to main content
  • Skip to primary sidebar

VANMY.NET

You are here: Home / Wordpress / Thêm nút Pin it của mạng xã hội Pinterest vào trang web wordpress

Thêm nút Pin it của mạng xã hội Pinterest vào trang web wordpress

Cùng với Facebook, Google Plus hoặc Twitter…, mục đích của việc khi bạn Like hoặc +1 một bài viết của bạn là để dễ dàng chia sẻ với tất cả bạn bè trên các trang mạng xã hội này, việc này giúp tăng lượt viếng thăm đến trang web của bạn.

Hiện nay, trang mạng xã hội mới nổi đang rất hot đó là Pinterest được xem là một nguồn giúp tăng thêm lượt viếng thăm cũng như quảng cáo cho web bạn. Sau đây là cách thêm nút “Pin it” vào blog wordpress của bạn, một nút để chia sẽ bài viết lên Pinterest giống như nút Like của Facebook hay +1 của Google Plus .

Đầu tiên, bạn cần dán đoạn code dưới đây vào file footer.php trước thẻ </body>

<script type="text/javascript">
(function() {
    window.PinIt = window.PinIt || { loaded:false };
    if (window.PinIt.loaded) return;
    window.PinIt.loaded = true;
    function async_load(){
        var s = document.createElement("script");
        s.type = "text/javascript";
        s.async = true;
        s.src = "http://assets.pinterest.com/js/pinit.js";
        var x = document.getElementsByTagName("script")[0];
        x.parentNode.insertBefore(s, x);
    }
    if (window.attachEvent)
        window.attachEvent("onload", async_load);
    else
        window.addEventListener("load", async_load, false);
})();
</script>

Sau đó bạn có thêm đoạn code dưới đây vào file single.php trong themes mà bạn chọn:

<?php $pinterestimage = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); ?>
<a href="http://pinterest.com/pin/create/button/?url=<?php echo urlencode(get_permalink($post->ID)); ?>&media=<?php echo $pinterestimage[0]; ?>&description=<?php the_title(); ?>" class="pin-it-button" count-layout="vertical">Pin It</a>

 

Hoặc với 1 đoạn shortcode duy nhất sau đây bạn có thể dán vào trong file functions.php của themes bạn đang dùng:

<?php
function get_pin($atts) {
$pinterestimage = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
return '<a href="http://pinterest.com/pin/create/button/?url' . urlencode(get_permalink($post->ID)) . '&media=' . $pinterestimage[0] . '&description=' . get_the_title() .'" class="pin-it-button" count-layout="vertical">Pin It</a>'; }

add_shortcode('pin', 'get_pin');
?>

Chúc bạn thành công!

Bài viết liên quan:

  1. Thêm chức năng tìm kiếm của Google vào trang wordpress của bạn
  2. Plugin thêm nút Like của Facebook vào trong WordPress
  3. Cách thêm Avatar mới trong WordPress
  4. Thêm trang web bạn vào bộ máy tìm kiếm
  5. Tăng cường sức mạnh của mạng xã hội cho WordPress
  6. Sử lý lỗi trắng trang khi update bài viết
  7. Làm đẹp trang WordPress dịp Giáng Sinh
Previous Post: « Đã có WordPress cho Android 2.0.5
Next Post: Thêm chức năng tìm kiếm của Google vào trang wordpress của bạn »

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

  • Home
  • WordPress
    • Plugins
    • Themes
  • SEO
    • Onpage
    • Offpage
  • Social Media
    • Google Plus
    • Facebook
  • Blogging
    • Domain
    • Hosting
    • Khác
  • Liên hệ
  • Site map

Copyright 2009 by vanmy.net