Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2015-04-17 00:51:36

gfdesign
Member
From: Argentina
Registered: 2009-04-20
Posts: 401

Help with meta og tags

Dear TXP users
I want to use these tags in order to optimize the pages so Facebook can read the main contents when they are shared.

My problem is that my client wanted enabled the WYSWYG editor in the excerpt field, so when I use them so:

<meta property="og:title" content='<txp:title />' />
<meta property="og:description" content='<txp:excerpt />' />
<meta property="og:image" content='<txp:upm_article_image><txp:upm_img_full_url /></txp:upm_article_image>' />

I get html tags in the source code:

<meta property="og:title" content='Sinfonía&#160;Natural' />
<meta property="og:description" content='<p class="MsoNormal"><span lang="ES">&#8203;Emplazado en la localidad balnearia de Monte</span><span lang="ES">en un entorno agreste y arbolado caracterizado como barrio parque, el arquitecto desarroll&#243; un proyecto de vivienda unifamiliar de uso temporario que combina a la perfecci&#243;n materiales y texturas.</span></p>
<p>&#160;</p>' />
<meta property="og:image" content='http://localhost/site01/images/411.png' />

This sometimes causes a break in the layout.
Is there any way to get the excerpt text but without these html tags?
Thanks

Last edited by gfdesign (2015-04-17 01:12:49)

Offline

#2 2015-04-17 07:33:25

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: Help with meta og tags

Hola Fernando, try to replace <txp:excerpt /> with

<txp:php>echo strip_tags(parse('<txp:excerpt />'));</txp:php>

Offline

#3 2015-04-17 15:00:40

whocarez
Plugin Author
From: Germany/Ukraine
Registered: 2007-10-08
Posts: 305
Website GitHub Twitter

Re: Help with meta og tags

I personally use the following:
<meta property="og:title" content='<txp:title no_widow="0" /> - <txp:site_name />' /> <meta property="og:description" content='<txp:rah_function call="strip_tags,trim"><txp:excerpt /></txp:rah_function>' />

no_widow="0" to get rid of the space &#160; and trim after strip_tags also because of spaces on the beginning and the end of the excerpt after removing the tags.

You have to install rah_function

Offline

#4 2015-04-17 18:29:47

gfdesign
Member
From: Argentina
Registered: 2009-04-20
Posts: 401

Re: Help with meta og tags

Hey guys.
Thanks so much for your helpful answers. Both worked.
However, I am not able to display the article image when the user tries to share an individual article on Facebook.
I’ve put all the necessary og.tags but it doesn’t work. Even, I test my site using Facebook Developer Tool. Open Graph Object Debugger and it gives me:

Object at URL ‘http://www.yoursite.com’ of type ‘website’ is invalid because a required property ‘og:title’ of type ‘string’ was not provided.

This is the site if you want take a look in the code.
Do you have the same problem?

Offline

#5 2015-04-17 18:44:17

whocarez
Plugin Author
From: Germany/Ukraine
Registered: 2007-10-08
Posts: 305
Website GitHub Twitter

Re: Help with meta og tags

I don’t know what is causing this error. But Facebook shows you at “See exactly what our scraper sees for your URL” what they found.
For your url http://www.revistadeck.com/nota/481/Estilo+Vintage FB sees only this:

<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title></title>
<script>var y=window</script><script>var x={o:'/AZeoPZ/nota/481/Estilo+Vintage',c:1},z=1;function rsu(h){return(x.o).substr(0,x.c)+(x.o).substr(x.c+h)}y.location.assign(rsu(z))</script>
</head></html>

It is the same if I open this page in my browser, play a little bit around and check after a while the source. Then I get the same. So I suggest that one of your javascripts is causing this.

Last edited by whocarez (2015-04-18 09:37:40)

Offline

#6 2015-04-17 19:29:47

gfdesign
Member
From: Argentina
Registered: 2009-04-20
Posts: 401

Re: Help with meta og tags

Yes, it’s true. However, I have nothing enabled related to GZIP compression or something. It’s strange because every time I take a look into the rendered HTML code, I don’t see as Facebook does.
I guess I’ll have to contact the hosting support for asking.
Thanks

Offline

#7 2015-04-18 09:31:48

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,137
GitHub

Re: Help with meta og tags

Nice looking site. Try moving the scripts to the bottom of the page, outside of the head. I had a look and most of the script references can safely be moved to before the closing body tag.

Also, perhaps not directly related, try using the minified versions of scripts where they exist, or compress them down. There’s a 3.5MB page payload on http://www.revistadeck.com/nota/481/Estilo+Vintage which can be easily reduced. The images I checked look pretty optimised, but minifying JS and CSS might eke the size down to under 3MB, or even better.

Offline

#8 2015-04-18 09:43:55

whocarez
Plugin Author
From: Germany/Ukraine
Registered: 2007-10-08
Posts: 305
Website GitHub Twitter

Re: Help with meta og tags

@gfdesign
If you have found, what is causing this error, you can of course start to optimize your site a little bit more. Try to combine your CSS and JS and then minify them. With aks_header or pat_speeder you can strip white spaces on the fly in your pages and reduce the loading and rendering time.

Offline

#9 2015-04-18 12:37:12

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: Help with meta og tags

gfdesign wrote #290103:

It’s strange because every time I take a look into the rendered HTML code, I don’t see as Facebook does.

I’m not sure that Facebook executes your javascript redirection. Just a guess, though.

Offline

#10 2015-04-24 19:12:33

gfdesign
Member
From: Argentina
Registered: 2009-04-20
Posts: 401

Re: Help with meta og tags

People, thanks for your suggestions. Finally, I’ve simplified the code as below:

<meta property="og:site_name" content="<txp:site_name />" /> 
<meta property="fb:admins" content="125099240859704" /> 
<meta property="og:type" content="article" />
<meta property="og:url" content="<txp:page_url />" />
<meta property="og:image" content="<txp:upm_article_image><txp:upm_img_full_url /></txp:upm_article_image>" />
<meta property="og:description" content='<txp:rah_function call="strip_tags,trim"><txp:excerpt /></txp:rah_function>' />
<meta property="og:title" content='<txp:title no_widow="0" />' /> 

But when I try to share on Facebook an individual article, sometimes FB doesn’t read the info from the page. Later, after several tries, FB is able to read all the info and just then share it.

Do you know why this happens?
Regards

Offline

#11 2015-04-24 23:02:44

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,473

Re: Help with meta og tags

With respect to this example: <txp:upm_article_image><txp:upm_img_full_url /></txp:upm_article_image>" />.

Do you know that the upm-plug-ins are no longer supported and that you can do the same with the native tags?

Offline

Board footer

Powered by FluxBB