Skip to content

Instantly share code, notes, and snippets.

@muhfaris
Last active December 8, 2016 09:52
Show Gist options
  • Save muhfaris/6a763a38feed1eb222167b3ab6f53d7c to your computer and use it in GitHub Desktop.
Save muhfaris/6a763a38feed1eb222167b3ab6f53d7c to your computer and use it in GitHub Desktop.
Share in Mobile Only
//Js
jQuery(document).ready(function() {
if (jQuery(window).width() < 768) {
jQuery(".share-entry").addClass("active_share");
}else {
jQuery(".share-entry").removeClass("active_share");
}
});
//fungsi php masukkan ke function.php theme nanti
add_filter( 'the_content', 'ilc_share' );
function ilc_share( $content ) {
global $post;
$upload_dir = wp_upload_dir();
$postlink = get_permalink($post->ID);
$posttitle = get_the_title($post->ID);
$html = '<div class="share-entry">';
$html .= '<a class="share-facebook share-frs" title="Share on Facebook" rel="external" href="http://www.facebook.com/share.php?u=' . $postlink . '"><img src="'.esc_url($upload_dir['baseurl'] . '/share_frs/facebook-white-60.png').'" alt="Facebook"></a>';
$html .= '<a class="share-twitter share-frs" title="Share on Twitter" rel="external" href="http://twitter.com/share?text='.$posttitle.'&url='.$postlink.'"><img src="'.esc_url($upload_dir['baseurl'] . '/share_frs/twitter-white-60.png').'" alt="Twitter"></a>';
$html .= '<a class="share-whatsapp share-frs" title="Share On Whatsapp" rel="external" href="whatsapp://send?text='.$postlink.'"><img src="'.esc_url($upload_dir['baseurl'] . '/share_frs/whatsapp-white-60.png').'" alt="Whatsapp"></a>';
$html .= '<a class="share-line share-frs" title="Share On Line" rel="external" href="http://line.me/R/msg/text/?'.$postlink.'"><img src="'.esc_url($upload_dir['baseurl'] . '/share_frs/lineapp-white-60.png').'" alt="Line"></a>';
$html .= '</div>';
//css
.share-facebook{background:#3b5998}.share-frs{display:inline-block;width:25%;color:#fff;box-sizing:border-box;padding:10px;position:relative;text-align:center;cursor:pointer;vertical-align:middle;line-height:0;height:50px}.share-frs img{box-shadow:initial!important;height:30px;width:30px}.share-twitter{background:#00aced}.share-whatsapp{background:#1d9e11}.share-line{background:#01c312}.share-entry{position:fixed;z-index:100;height:50px;width:100%;background:0 0;padding:0;color:#000;box-sizing:border-box;font-size:0;bottom:0;left:0;display:none}.share-facebook a{color:#0073b7}.active_share{display:block!important}
//function
function share_frs() {
wp_register_script( 'share_frs_js', get_template_directory_uri() . ('/share_frs.js'), array(), '1.0', true );
wp_enqueue_script('share_frs_js');
}
add_action( 'wp_enqueue_scripts', 'share_frs', 999 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment