Pair of Vintage Old School Fru
Home » Scripts And Tips » General scripts » Facebook og tags for blogs
 This thread is closed
This script will create OG:meta tags for xtgem blog posts
I have tested this on this sites blog and it works
NOTE: facebook may have old versions of your share data cached and it will be up to you to get this reset
https://developers.facebook.com/tools/debug/sharing/batch/
from what I can tell you have to request 'rescrape' one post at a time

This will only work on blogs that are output by xtscript and have a twig template file
The script creates AUTOMATIC facebook og meta tags using the posts title text content canonical URI and the FIRST image found in the post[/b]

FIRST go to https://developers.facebook.com register start a project and get an app_id this then needs to go in the fb:ap_id meta tag in the last line of the main xt:script

This needs to go in your blog twig just below the {% elseif view == 'entry' %} Line
<!--og_tags={{data.post.url|split('?')[0]}}||{{ data.post.title|replace({('$'):'&#36;',('('):'&#40;'})|raw }}||{{data.post.content|striptags|trim|replace({('$'):'&#36;',('('):'&#40;',('"'):'&#34;', ('\n'): ' ', ('\r'): ''})[:300]|raw}}||{{data.post.content|split('<img')[1]|split('src="')[1]|split('"')[0]}}-->
Copy code


Here is the actual xtscript code it needs it needs to be inserted after the blog has been assigned to a xtscript variable ( this expects it to be $blog )
# FB OG TAGS 
get __xtblog_entry
 if not $__xtblog_entry or not $blog
  var $fb_og ={{
<meta content="DEFAULT TITLE" property='og:title' />
<meta content="SITE DESCRIPTION (max 300 chars)" property='og:description' />
<meta content='<xt:url/>' property='og:url' />
<meta content='website' property='og:type' />
}}
  goto @skip_og
  endif
  var $og_tags_s = call strpos $haystack=$blog;$needle=og_tags=
  var $og_tags_s = ($og_tags_s+8)
  var $og_tags_e = call strpos $haystack=$blog;$needle=-->;$offset=$og_tags_s
  var $og_tags = call substr $val=$blog;$start=$og_tags_s;$length=($og_tags_e-$og_tags_s)

  var $og_url_s = 0
  var $og_url_e = call strpos $haystack=$og_tags;$needle=||;$offset=$og_title_s
  var $og_url = call substr $val=$og_tags;$start=$og_url_s;$length=($og_url_e-$og_url_s)

  var $og_title_s =($og_url_e+2) 
  var $og_title_e = call strpos $haystack=$og_tags;$needle=||;$offset=$og_title_s
  var $og_title = call substr $val=$og_tags;$start=$og_title_s;$length=($og_title_e-$og_title_s)

  var $og_descr_s = ($og_title_e+2)
  var $og_descr_e = call strpos $haystack=$og_tags;$needle=||;$offset=$og_descr_s  
  var $desc_len = ($og_descr_e-$og_descr_s)
  var $og_descr = call substr $val=$og_tags;$start=$og_descr_s;$length=$desc_len
  var $og_descr= call str_replace $subject=$og_descr;$search=";$replace='
  if $desc_len >= 300
  var $spc=call chr $val=32
  var $lstspc=call strrpos $haystack=$og_descr;$needle=$spc
  var $og_descr= call substr $val=$og_descr;$start=0;$length=$lstspc
  endif

  var $og_img_s = ($og_descr_e+2)
  var $og_img_e = call strpos $haystack=$og_tags||;$needle=||;$offset=$og_img_s 
  var $og_img = call substr $val=$og_tags;$start=$og_img_s;$length=($og_img_e-$og_img_s)

var $fb_og = {{
<meta content='$og_url' property='og:url' />
<meta content='article' property='og:type' />
<meta content='$og_title' property='og:title' />
}}
if $og_descr
var $fb_og =$fb_og {{
<meta content="$og_descr" property='og:description' />
}}
endif
if $og_img
var $fb_og =$fb_og {{
<meta content='$og_img' property='og:image' />
}}
endif

@skip_og
var $fb_og =$fb_og {{
<meta content='YOUR AP ID MUST GO HERE' property='fb:app_id' /> 
}}

Copy code
you then need to add this to the <head> area of the blog page using text editor
{_$$fb_og|}
Copy code
#
 
1
Home » Scripts And Tips » General scripts » Facebook og tags for blogs
© graham 2018 : Please give credit for any of my code used