Created
February 16, 2016 01:17
-
-
Save anneallen/613d5a629eec7857f313 to your computer and use it in GitHub Desktop.
Add Open Graph Protocol tags to Genesis Child theme
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
//*Enqueue Font Awesome for icons | |
add_action( 'wp_enqueue_scripts', 'child_enqueue_scripts_styles' ); | |
function child_enqueue_scripts_styles() { | |
wp_enqueue_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css', array(), CHILD_THEME_VERSION ); | |
} | |
//*Add Open Graph Stuff | |
add_action( 'genesis_meta', 'child_add_ogstuff_single' ); | |
function child_add_ogstuff_single(){ | |
if (is_singular('post')){ | |
$imgurl =genesis_get_image( array( | |
'format' => 'url', | |
'size' => 'full', | |
) ); | |
$title=get_the_title(); | |
$url=get_permalink(); | |
$description=get_the_excerpt(); | |
echo ' <meta property="og:image" content="'.$imgurl.'" /> | |
<meta property="og:url" content="'.$url.'" /> | |
<meta property="og:title" content="'.$title.'" /> | |
<meta property="og:description" content="'.$description.'" />'; | |
}} | |
//*Social Icons Shortcode for use in loop | |
add_shortcode('socialshares','sc_socialshares'); | |
function sc_socialshares(){ | |
$url=get_permalink(); | |
$title=get_the_title(); | |
$returnstring= ' | |
<ul class="social-icons"> | |
<li><a class="socials facebook" href="https://www.facebook.com/sharer/sharer.php?u='.$url.'" target="_blank"><i class="fa fa-facebook"></i></a></li> | |
<li class="social twitter"><a class="socials" href="http://twitter.com/intent/tweet?status='.$title.'+'.$url.'" target="_blank"><i class="fa fa-twitter"></i></a></li> | |
<li class="social linkedin"><a class="socials" href="http://www.linkedin.com/shareArticle?mini=true&url='.$url.'&title='.$title.'&source=[SOURCE/DOMAIN]" target="_blank"><i class="fa fa-linkedin"></i></a></li> | |
</ul>'; | |
return $returnstring; | |
} | |
//*CSS | |
/* | |
Social Icons | |
-----------------------------------------------------------------------------------------------------*/ | |
ul.social-icons { | |
text-align: center; | |
margin:10px 10px 20px; | |
} | |
ul.social-icons li { | |
list-style-type: none; | |
display: inline-block; | |
} | |
ul.social-icons li a { | |
display: block; | |
width:40px; | |
height: 40px; | |
line-height: 40px; | |
color: #fff; | |
background: #004677; | |
margin:2px; | |
text-align: center; | |
border-radius: 3px; | |
} | |
ul.social-icons li a .fa { | |
font-size: 20px; | |
line-height: 40px; | |
} | |
ul.social-icons li a:hover { | |
color: #9bcae8; | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment