Here is a code snippet from a function method in a news aggregator. The messages that are available get the Pin It button if I can find the image with simpleHTMLDom.
// Pinterest /* Pinterest requires two bits of code, something like this: <a href="http://pinterest.com/pin/create/button/?url=http%3A%2F%2Fwww.muschamp.ca%2F&media=http%3A%2F%2Fwww.muschamp.ca%2Fimage.jpg&description=whatever" class="pin-it-button" count-layout="horizontal"><img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" /></a> Where you want the button ie here, and <script type="text/javascript" src="//assets.pinterest.com/js/pinit.js"></script> directly after the body tag just like Facebook new style button */ // I definitely miss how I did things in my previous code base, if there is no image should not be able to pin... if(($image != NULL) && ( ! strpos($image->src, '+')) && ( ! strpos($image->src, '%')) && (preg_match('|^http?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $image->src))) { // If I don't display a valid image, no sense in showing a Pin It button $html .= '<li>'; // Opening <li> // May want a more elaborate description... $html .= '<a href="http://pinterest.com/pin/create/button/?url=' . $item->get_permalink() . '&media=' . $image->src . '&description=' . $item->get_title() . '" class="pin-it-button" count-layout="horizontal"><img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" /></a></li>'; }
Designed, if proven, necessary for testing, as some valid URLs may not be accepted as valid on Pinterest Pinterest, at least that was what I discovered when testing. The "%" and "+" symbols seem to be especially unpleasant. Pinterest will not allow you to print small images or even very large images, but since I also used PHP to resize images in my news aggregator, I do not test this here, but this is what I need when adding Pinterest to your application.
source share