[WordPress] เพิ่มปุ่ม Pin it ของ Pinterest

ตอนนี้เว็บ Social Network อีกอันที่ผมว่าน่าสนใจก็คือ Pinterest

[Wordpress] เพิ่มปุ่ม Pin it ของ Pinterest [1]

Pinterest มันคืออะไร น้อง Bluemoon ได้เขียนอธิบายไว้อันนี้ครับ Pinterest

ส่วนผมจะมาอธิบายวิธีการใส่ปุ่ม Pin it ของมันให้ได้ไปใช้กันครับ โดยปุ่ม Pin it นั้นทางเว็บมีให้เรานำไปใช้งานได้อยู่แล้วที่ Pin it Button แต่เราจะนำมาประยุกต์ใช้งานกับเว็บ WordPress ของเรา

โดยเราเปิด footer.php เพื่อใส่ Code นี้ลงไปครับ

[js]
<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 = "https://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>
[/js]

และตำแหน่งไหนที่เราจะแปะปุ่ม Pin it ลงไป ก็ให้ใช้ Code นี้ครับ

[php]
<?php $pinterestimage = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), ‘full’ ); ?>
<a href="https://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>
[/php]

เราก็จะได้ปุ่ม Pin it มาใช้งานแล้วครับ


Posted

in

by

Comments

2 responses to “[WordPress] เพิ่มปุ่ม Pin it ของ Pinterest”

  1. […] Pin it ของ Pinterest ในเว็บ WordPress ของเราแล้ว ([WordPress] เพิ่มปุ่ม Pin it ของ Pinterest) มาครั้งนี้ก็มาแนะนำ Plugin […]

  2. surapath junthasri Avatar
    surapath junthasri

    surapath junthasri

Leave a Reply to surapath junthasri Cancel reply

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