-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpinimageshortcode.php
More file actions
59 lines (45 loc) · 1.6 KB
/
pinimageshortcode.php
File metadata and controls
59 lines (45 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/*
Plugin Name: Pin Image Shortcode
Plugin URI: https://github.com/designedbyscience/Wordpress-Pin-Image-Shortcode-Plugin
Description: Add Pin It button to images that appears on hover
Version: 1.0
Author: Matthew Richmond and Eric Haseltine
Author URI: http://choppingblock.com
License: MIT/Expat
*/
/*** Post Image Hovers ***/
function cb_pinImage_func( $atts ) {
$styleUrl = plugins_url('pinimage.css', __FILE__);
$styleFile = WP_PLUGIN_DIR . '/pin-image/pinimage.css';
if ( file_exists($styleFile) ) {
wp_register_style('pinimagestyle', $styleUrl);
wp_enqueue_style( 'pinimagestyle');
}
$scriptUrl = plugins_url('pinimage.js', __FILE__);
$scriptFile = WP_PLUGIN_DIR . '/pin-image/pinimage.js';
if(file_exists($scriptFile)){
wp_register_script('pinimagejs', plugins_url('pinimage.js', __FILE__));
wp_enqueue_script('jquery');
wp_enqueue_script('pinimagejs');
}
extract( shortcode_atts( array(
'src' => '',
'title' => '',
'width' => '',
'height' => ''
), $atts ) );
$url = get_permalink();
$inlineStyle = "";
$inlineWH = "";
if($width != '' && $height != ''){
$inlineStyle = "style='width: {$width}; height: {$height};'";
$inlineWH = "width='{$width}' height='{$height}'";
}
return "<div class='img-hover' {$inlineStyle}>
<a href='{$url}'><img src='{$src}' {$inlineWH} alt title='{$title}' /></a><div class='img-hover-meta'>
<a href='http://pinterest.com/pin/create/button/?url={$url}&media={$src}&description={$title}' class='pin-it-button' count-layout='none'>Pin It</a>
</div></div>";
}
add_shortcode( 'pinImage', 'cb_pinImage_func' );
?>