Skip to content

Instantly share code, notes, and snippets.

@koffisani
Created February 1, 2017 08:25
Show Gist options
  • Save koffisani/881a0c475630bd7b29633365d7edab38 to your computer and use it in GitHub Desktop.
Save koffisani/881a0c475630bd7b29633365d7edab38 to your computer and use it in GitHub Desktop.
Get data from meta tags in javascript
<script type='text/javascript'>
/*
* Here we try to retreive a data from <meta name="bitly:url" content=""/>
*/
var BitlyURL = jQuery('meta[property="bitly:url"]').attr('content');
var url = "";
if ( typeof BitlyURL !== 'undefined' ){
url = BitlyURL;
}
else
url = "<?= the_permalink(); ?>";
jQuery(document).ready(function(){
var ta = document.getElementById('twitter_<?= $post->ID ?>');
ta.href="https://twitter.com/home/?status=<?php the_title(); ?> - " + url;
var fa = document.getElementById('facebook_<?= $post->ID ?>');
fa.href="https://www.facebook.com/sharer.php?u=" + url + "&amp;t=<?php the_title(); ?>";
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment