danpros / htmly

Simple and fast databaseless PHP blogging platform, and Flat-File CMS
https://www.htmly.com
GNU General Public License v2.0
1.07k stars 261 forks source link

Add og and twitter taggs #162

Closed Silverunit closed 9 years ago

Silverunit commented 9 years ago

Hi,

Does anyone have an idea about this. I use a plan html template and would like to add og and twitter tags. Use the code below:

<meta name="twitter:card" content="summery" />
<meta name="twitter:site" content="@silverunit" />
<meta name="twitter:title" content="<?php echo $p->title ?> | Silverunit Systems" />
<meta name="twitter:description" content="<?php echo get_description($p->body, $p->url) ?>" />
<meta name="twitter:url" content="<?php echo $p->url ?>" />

In the layout file. It works on each post. That I could understand as $p marks posts. But when viewing the main page. The marks are showing the second post in the feed. Not the first or not the main config information.

Any thoughts? Best regards, Michael

danpros commented 9 years ago

Hello,

How about this:

<meta name="twitter:card" content="summery" />
<meta name="twitter:site" content="@silverunit" />
<meta name="twitter:title" content="<?php echo $title ?>" />
<meta name="twitter:description" content="<?php echo $description ?>" />
<meta name="twitter:url" content="<?php echo $canonical ?>" />
Silverunit commented 9 years ago

Hi,

Thanks for your answer. I could not get this either to work. Your answer did get me to work on this matter again. Have not been thinking about it for some time now.

I had missed one BIG thing, my bad, I needed to include it on the functions file and it looks like this:

//    <!-- META DATA open graph | title 90 char | description 200 char -->
$ogtype = '<meta property="og:type" content="website" />';
$ogtitle = '<meta property="og:title" content="' .  $title . ' | Silverunit Systems" />';
$ogdesc = '<meta property="og:description" content="' . $description . '" />';
$ogurl = '<meta property="og:url" content="' . $canonical . '" />';
//<meta property="og:image" content="http://www.silverunitsystems.se/images/share/silverunit-systems-feeds-nyheter.jpeg" /> 

//    <!-- META DATA twitter card | title 70 char | description 200 char -->
$tcard = '<meta name="twitter:card" content="summery" />';
$tsite = '<meta name="twitter:site" content="@silverunit" />';
$ttitle = '<meta name="twitter:title" content="' . $title . ' | Silverunit Systems" />';
$tdesc = '<meta name="twitter:description" content="' . $description . '" />';
$turl = '<meta name="twitter:url" content="' . $canonical . '" />';

But I ran in to another issue, the $title, $description and $canonical liked to output the total meta information. I then did change the first $title, $description and $canonical with adding a "h" in the name. Like this $htitle = '' . $title . ' | Silverunit Systems'; $hdescription = ''; and $hcanonical = '';

And then I did the same in if's for the out put. Now it works nice and as it should, i think.

Will creed you and this wonderful blogfunktion when we go live! Thanks again, Michael - sweden

danpros commented 9 years ago

Ah forgot if I move those variables into head_contents :) perhaps I will move it out for those purpose.

Silverunit commented 9 years ago

Yes I noticed that :) And If you do implement this feature do not forget to add "prefix="og: http://ogp.me/ns#" to the html tag. I think this would be nice to have for the share options you already have.