Browse Source

add featured_image_url to meta

windhamdavid 4 years ago
parent
commit
55d38576fa
1 changed files with 28 additions and 28 deletions
  1. 28 28
      inc/tweaks.php

+ 28 - 28
inc/tweaks.php

@@ -175,36 +175,36 @@ add_filter('language_attributes', 'doctype_opengraph');
 
 
 function dw_opengraph() {
 function dw_opengraph() {
     global $post;
     global $post;
-
-    if(is_single()) {
-        if(has_post_thumbnail($post->ID)) {
-            $img_src = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), 'full');
-			$img_src = $img_src[0];
-        } else {
-            $img_src = get_stylesheet_directory_uri() . '/img/opengraph_image.jpg';
-        }
-        if($excerpt = $post->post_excerpt) {
-            $excerpt = strip_tags($post->post_excerpt);
-            $excerpt = str_replace("", "'", $excerpt);
-        } else {
-            $excerpt = get_bloginfo('description');
-        }
+    if (is_single()) {
+      if (has_post_thumbnail($post->ID)) {
+        $img_src = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), 'full'); $img_src = $img_src[0];
+      } elseif ( metadata_exists( 'post', get_the_ID(), 'featured_image_url' ) ){
+        $img_src = get_post_meta( get_the_ID(), 'featured_image_url', true );
+      } else {
+        $img_src = get_stylesheet_directory_uri() . '/img/opengraph_image.jpg';
+      }
+      if($excerpt = $post->post_excerpt) {
+        $excerpt = strip_tags($post->post_excerpt);
+        $excerpt = str_replace("", "'", $excerpt);
+      } else {
+        $excerpt = get_bloginfo('description');
+      }
 ?>
 ?>
-    <meta property="og:title" content="<?php echo the_title(); ?>"/>
-    <meta property="og:description" content="<?php echo $excerpt; ?>"/>
-    <meta property="og:type" content="article"/>
-    <meta property="og:url" content="<?php echo the_permalink(); ?>"/>
-    <meta property="og:site_name" content="<?php echo get_bloginfo(); ?>"/>
-    <meta property="og:image" content="<?php echo $img_src; ?>"/>
-	<meta property="fb:app_id" content="203136806559589" />
-	<meta name="twitter:site" content="@windhamdavid">
-	<meta name="twitter:creator" content="@windhamdavid">
-	<meta name="twitter:title" content="<?php echo the_title(); ?>">
-	<meta name="twitter:description" content="<?php echo $excerpt; ?>">
-	<meta name="twitter:image" content="<?php echo $img_src; ?>">
+  <meta property="og:title" content="<?php echo the_title(); ?>"/>
+  <meta property="og:description" content="<?php echo $excerpt; ?>"/>
+  <meta property="og:type" content="article"/>
+  <meta property="og:url" content="<?php echo the_permalink(); ?>"/>
+  <meta property="og:site_name" content="<?php echo get_bloginfo(); ?>"/>
+  <meta property="og:image" content="<?php echo $img_src; ?>"/>
+  <meta property="fb:app_id" content="203136806559589" />
+  <meta name="twitter:site" content="@windhamdavid">
+  <meta name="twitter:creator" content="@windhamdavid">
+  <meta name="twitter:title" content="<?php echo the_title(); ?>">
+  <meta name="twitter:description" content="<?php echo $excerpt; ?>">
+  <meta name="twitter:image" content="<?php echo $img_src; ?>">
 <?php
 <?php
     } else {
     } else {
-        return;
+      return;
     }
     }
 	 $content = do_shortcode( apply_filters( 'the_content', $post->post_content ) );
 	 $content = do_shortcode( apply_filters( 'the_content', $post->post_content ) );
 	 $media_url = get_post_meta( get_the_ID(), 'media', true );
 	 $media_url = get_post_meta( get_the_ID(), 'media', true );
@@ -226,7 +226,7 @@ function dw_opengraph() {
 <?php
 <?php
     } else {
     } else {
 ?>
 ?>
-	<meta name="twitter:card" content="summary_large_image">
+  <meta name="twitter:card" content="summary_large_image">
 <?php
 <?php
     }
     }
 }
 }