Merge pull request #24 from ascribe/fix/sharing

Fix Twitter Cards & Facebook OpenGraph
This commit is contained in:
Matthias Kretschmann 2016-01-07 17:28:31 +01:00
commit 8202e9764a
3 changed files with 29 additions and 61 deletions

View File

@ -1,55 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: sarahetter
* Date: 15-09-17
* Time: 4:48 PM
*/
//<editor-fold desc="Init">
global $passInTitle;
$description = '';
$image = '';
$title = '';
$url = get_bloginfo('wpurl');
//</editor-fold>
//<editor-fold desc="Get Title">
if(isset($passInTitle)) {
$title = $passInTitle;
}
else {
$title = get_the_title();
}
if (strpos($title, 'Home') !== false)
{
$title = '';
}
else {
$title .= ' | ';
}
$title .= get_bloginfo();
//</editor-fold>
//<editor-fold desc="Get Description">
$description = get_the_excerpt();
if (empty($description)) {
$content = get_field('subtemplate')[0]['content'];
if (!empty($content)) {
$description = substr(strip_tags($content),0,140)."...";
}
}
if (empty($description)) {
$description = get_bloginfo('description');
}
//</editor-fold>
//<editor-fold desc="Get Image">
$image = get_field('header_image')['url'];
if (empty($image)) {
$image = WPTHEME_TEMPLATE_URL.'/images/ico/apple-touch-icon-152x152.png';
}
//</editor-fold>

View File

@ -12,6 +12,17 @@ $description = '';
$image = '';
$title = '';
$url = get_bloginfo('wpurl');
$permalink = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$twitter = '@ascribeio';
if ( has_post_thumbnail() ) {
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' );
$shareimage = $large_image_url[0];
} else if ( get_field('header_background_image') != '' ) {
$shareimage = get_field('header_background_image')['url'];
} else {
$shareimage = WPTHEME_TEMPLATE_URL . '/images/ico/apple-touch-icon-180x180.png';
}
//</editor-fold>
//<editor-fold desc="Get Title">
@ -35,7 +46,15 @@ $title .= get_bloginfo();
//</editor-fold>
//<editor-fold desc="Get Description">
// Heads Up! This doesn't work cause it's outside of loop.
// But the following functions should handle all other use cases.
$description = get_the_excerpt();
if ( get_field('header_tagline') != '' ) {
$description = strip_tags(get_field('header_tagline'));
}
if (empty($description)) {
$content = get_field('subtemplate')[0]['content'];

View File

@ -15,6 +15,9 @@ if (!isset($headColour)) {
if (is_home()) {
$title = "Blog | ascribe";
}
if ( is_category() || is_tag() ) {
$title = single_term_title( '', false ) . ' | Blog | ascribe';
}
?>
<!doctype html>
@ -32,21 +35,22 @@ if (is_home()) {
<base href="<?php echo $url; ?>">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0">
<meta name="description" content="<?php echo $description ?>">
<meta property="og:title" content="<?php echo $title; ?>" />
<meta property="og:type" content="website" />
<meta property="og:url" content="<?php echo $url; ?>" />
<meta property="og:image" content="<?php echo $image; ?>" />
<meta property="og:url" content="<?php echo $permalink; ?>" />
<meta property="og:image" content="<?php echo $shareimage; ?>" />
<meta property="og:site_name" content="<?php echo get_bloginfo(); ?>" />
<meta name="twitter:card" content="summary">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="<?php echo $title; ?>">
<meta name="twitter:description" content="<?php echo $description ?>">
<meta name="twitter:image:src" content="<?php echo $image; ?>">
<meta name="twitter:domain" content="<?php echo $url; ?>">
<meta name="twitter:image" content="<?php echo $shareimage; ?>">
<meta name="twitter:site" content="<?php echo $twitter; ?>">
<meta itemprop="name" content="<?php echo $title; ?>">
<meta itemprop="description" content="<?php echo $description ?>">
<meta itemprop="image" content="<?php echo $image; ?>">
<meta itemprop="image" content="<?php echo $shareimage; ?>">
<link rel="apple-touch-icon" sizes="57x57" href="<?php echo WPTHEME_TEMPLATE_URL; ?>/images/ico/apple-touch-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="<?php echo WPTHEME_TEMPLATE_URL; ?>/images/ico/apple-touch-icon-60x60.png">