rodrigobertin
1/17/2018 - 12:47 PM

Social Share WP

<?php

/**
 * Get actual URL
 */
function getUrlPost( $encode = true ) {
	global $wp;
	$current_url = home_url( add_query_arg( array(),$wp->request ) );

	return $encode ? urlencode( $current_url ) : ( $current_url );
}
export default class Shares {
  
  constructor() {
    // ------------------------------------------------------ >
    // Share button
    
    $('.js-share-btn').on('click',function (e) {
      e.preventDefault();
      const $btn     =$(e.currentTarget);
      const tmp_left =($(window).width() / 2)-($btn.attr('data-popup-width') / 2);
      const tmp_specs=`height=${$btn.attr('data-popup-height')},width=${$btn.attr('data-popup-width')},scrollTo,resizable=1,scrollbars=1,location=0,top=165,left=${tmp_left}`;
      window.open(this.href,'Share',tmp_specs);
    });
  }
  
}
<div class="share">

  <ul class="social-container">
    {{--Twitter--}}
    <li class="social-twiiter">
      <a href="http://twitter.com/share?url=%2F&amp;text={{ the_title() }} {{ getUrlPost() }}" class="js-share-btn" data-service="Twitter" data-popup-width="555" data-popup-height="395" target="_blank">
          <span>
            @php include App\svg_path('socials/twitter.svg'); @endphp
          </span>
      </a>
    </li>

    {{--Facebook--}}
    <li class="social-facebook">
      <a href="http://www.facebook.com/sharer/sharer.php?p[url]={{ getUrlPost() }}"
         class="js-share-btn"
         data-service="Facebook"
         data-popup-width="555"
         data-popup-height="395" target="_blank">
        <span>
          @php include App\svg_path('socials/facebook.svg'); @endphp
        </span>
      </a>
    </li>

    {{-- Linkedin --}}
    <li class="social-linkedin">
      <a href="https://www.linkedin.com/shareArticle?mini=true&url={{ getUrlPost() }}&media={{ the_title() }}"
         class="js-share-btn"
         data-service="Linkedin"
         data-popup-width="555"
         data-popup-height="395" target="_blank">
        <span>
          @php include App\svg_path('socials/linkedin.svg'); @endphp
        </span>
      </a>
    </li>

    {{-- Google Plus --}}
    <li class="social-google">
      <a href="https://plus.google.com/share?url={{ getUrlPost() }}"
         class="js-share-btn"
         data-service="Google Plus"
         data-popup-width="600"
         data-popup-height="400"
         target="_blank">
        <span>
          @php include App\svg_path('socials/google_plus.svg'); @endphp
        </span>
      </a>
    </li>

    {{-- Email --}}
    <li class="social-email">
      <a href="mailto:?body={{ getUrlPost(false) }}&subject={{ the_title() }}"
         class=""
         data-service="Email"
         data-popup-width="600"
         data-popup-height="400"
         target="_blank">
        <span>
          @php include App\svg_path('socials/mail.svg'); @endphp
        </span>
      </a>
    </li>

  </ul>
</div>