3rd party social media buttons and Facebook OG Metatag

slart

Joined: 2013-11-11
Posts: 112
Posted: Tue, 2014-06-24 13:37

Facebook OG Metatags and truncate description.

Step by step.

- activate Module: tag (You can do it from the sidebar take in the admin settings, when you don't use it.)
- install and activate Module: metadescription

Edit via FTP:
/modules/metadescription/views/metadescription_block.html.php

complete php file textblock (please change "you name" and "youwebsite.de"):

Quote:
<?php defined("SYSPATH") or die("No direct script access.") ?>

<?

$item = $theme->item;

$metaTags = "";

if (count($tags) > 0) {

for ($counter=0; $counter<count($tags); $counter++) {

if ($counter < count($tags)-1) {

$metaTags = $metaTags . html::clean($tags[$counter]->name) . ",";

} else {

$metaTags = $metaTags . html::clean($tags[$counter]->name);

}

}

}

// If $metaTags is empty, use the item's title instead.

if ($metaTags == "") {

$metaTags = html::clean($item->title);

}

$metaDescription = "";

$metaDescription = trim(nl2br(html::purify($item->description)));

// If description is empty, use title instead.

if ($metaDescription == "") {

$metaDescription = html::clean($item->title);

}

// If this page belongs to a tag, use the description of the first item instead.

if ($theme->tag()) {

if (count($children) > 0) {

$metaDescription = trim(nl2br(html::purify($children[0]->description)));

}

}

// If it's still empty, use $metaTags.

if ($metaDescription == "") {

$metaDescription = $metaTags;

}

// Strip HTML

$metaDescription = strip_tags($metaDescription);

// Strip Line Breaks

$metaDescription = str_replace("\n", " ", $metaDescription);

// Limit Description to 150 characters.

$metaDescription = substr($metaDescription, 0,150);

?>
<meta property="og:description" content="<?= $metaDescription ?> ..." />

<meta property="og:title" content="<?= $theme->item()->title ?>" />

<meta property="og:image" content="<?= $item->thumb_url(true) ?>" />

<meta property="og:site_name" content="youwebsite.de" />

<meta name="keywords" content="<?= $metaTags ?>" />

<meta name="description" content="<?= $metaDescription ?> ..." />

<meta name="author" content="You Name" />

<meta name="Generator" content="You Name | www.youwebsite.de" />

You can include many more "og:..." metatags with this form.

I use AddThis 3rd party social media buttons in a code block with module: code block.

 
jelzo

Joined: 2008-04-10
Posts: 67
Posted: Thu, 2014-06-26 17:16

It's probably better to replace the hardcoded website url with: <?= url::site("tag/add/3/foo") ?>