Last active
March 31, 2016 21:31
-
-
Save igorbenic/4e19990f74ed911a91bd37a94a231286 to your computer and use it in GitHub Desktop.
How to Create Sharing Buttons similar to Jetpack | http://www.ibenic.com/create-sharing-buttons-similar-jetpack/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function my_share_render_in_content( $content ) { | |
ob_start(); | |
?> | |
<ul id="my_share" class="my_share"> | |
<li> | |
<a href="<?php the_permalink();?>?my_share=facebook">Facebook</a> | |
</li> | |
<li> | |
<a href="<?php the_permalink();?>?my_share=twitter">Twitter</a> | |
</li> | |
</ul> | |
<?php | |
$content .= ob_get_contents(); | |
ob_end_clean(); | |
return $content; | |
} | |
add_action( 'the_content', 'my_share_render_in_content'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
$( document ).ready( function(){ | |
$("#my_share a").on('click', function(e){ | |
e.preventDefault(); | |
var href = $( this ).attr("href"); | |
window.open( href, 'Share', 'width=600, height=400'); | |
}) | |
}); | |
})(jQuery); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.my_share { | |
padding:0; | |
margin:0; | |
list-style: none; | |
display: block; | |
width:100%; | |
} | |
.my_share:after { | |
display: table; | |
content: ''; | |
clear: both; | |
} | |
.my_share li { | |
float: left; | |
} | |
.my_share a { | |
padding: 0.5em .75em; | |
background-color:white; | |
color: black; | |
border: 1px solid gray; | |
box-shadow: 0px 1px 1px #ccc; | |
} | |
.my_share a:hover, | |
.my_share a:focus { | |
background-color:black; | |
color:white; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment