Metatag Description and Open Graph Metatag Description?

slart

Joined: 2013-11-11
Posts: 112
Posted: Sat, 2013-12-14 16:53

Hello,
I want to insert in my Gallery3 with the Theme Dark Canvas on the homepage and in each album a block of text with different content.
I have tried the module code block and Custom Fields, but these are not suitable.

Currently I have the text blocks inserted as the description there where I have moved the php code for that.

Quote:
themes/clean_canvas/views/info_block.html.php
delete line 7 to 12
<? if ($item->description): ?>
<li>
<strong class="caption"><?= t("Description:") ?></strong>
<?= nl2br(html::purify($item->description)) ?>
</li>
<? endif ?>

themes/clean_canvas/views/album.html.php
insert on line 16 befor line with that: <div id="g-info">
<? if ($item->description): ?>
<li>
<strong class="caption"><?= t("") ?></strong>
<?= nl2br(html::purify($item->description)) ?>
</li>
<? endif ?>

But this is a bad solution because of the meta description is too long.
edit: i have make this additional under the photos in the photo pages.

Is there a better solution? I need this only for the start page and the album pages.

Please see in the Attachement. Here is a screenshot. (I have it pixelated.)

AttachmentSize
Zwischenablage05.jpg348.53 KB
 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Sat, 2013-12-14 17:47

Your screen shot does not help at all.

Quote:
But this is a bad solution because of the meta description is too long.

So you want to truncate the meta tag?

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
slart

Joined: 2013-11-11
Posts: 112
Posted: Sun, 2013-12-15 13:10

Hi floridave, yes I would like to shorten the text in the meta tag description.

I have tried the module text truncate, but that does not work in my Gallery, and bring not probably the solution.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Sun, 2013-12-15 17:27

OK how is the meta description generated? Is it a module ( what module) or is it built into the theme?

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
slart

Joined: 2013-11-11
Posts: 112
Posted: Sun, 2013-12-15 20:22

Hi Dave, I have (now) 2 different meta tags. The normal metatags and the Open Graph meta tags.

Normal: <meta name="_______" content="__________" />
Open Graph: <meta property="og:________" content="_______"/>

The normal are manually inserted into themes/clean_canvas/views/page.html.php. With solid content (not so good).
The Open Graph is from the module social share.

OK, I just think the normal meta tags description could also be in the social share module. tricky ;)

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Sun, 2013-12-15 23:46

So the social share module has a OG: meta tag for the description you want to be truncated?

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Mon, 2013-12-16 00:43
Quote:
With solid content (not so good).

Explain with code you are using.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
slart

Joined: 2013-11-11
Posts: 112
Posted: Mon, 2013-12-16 11:28

Hi Dave, that is the Module social share: http://codex.galleryproject.org/Gallery3:Modules:social_share

That is the source code from the modules/social_share/helpers/social_share_themes.php

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

/**

...

*/

class social_share_theme_Core {

static function head($theme) {

$impageonly = module::get_var("social_share", "general_impage_only");

$showblock = !$impageonly || ($impageonly && ($theme->page_subtype == "photo") || ($theme->page_subtype == "movie"));

if ($showblock && $theme->item()) {

$item = $theme->item();

$url = $item->thumb_url(true);

$appId = module::get_var("social_share", "facebook_like_appId");

$adminId = module::get_var("social_share", "facebook_like_adminId");

$site_name = module::get_var("social_share", "facebook_like_site_name");

$selfURL = url::abs_current(true);

return "\t<meta property=\"og:image\" content=\"$url\"/>

<meta property=\"og:title\" content=\"$item->title\"/>

<meta property=\"og:description\" content=\"$item->description\">

<meta property=\"og:type\" content=\"article\"/>

<meta property=\"og:url\" content=\"$selfURL\"/>

<meta property=\"og:site_name\" content=\"$site_name\"/>

<meta property=\"fb:app_id\" content=\"$appId\"/>

<meta property=\"fb:admins\" content=\"$adminId\"/>";

}

}

}

I have expanded it with the metatag og:description. Thanks to tempg http://galleryproject.org/node/112388#comment-407512

The normal Metatag source code in the themes/clean_canvas/views/page.html.php , which I have added manually.

Quote:
<?php defined("SYSPATH") or die("No direct script access.") ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <?= $theme->html_attributes() ?> xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

<meta name="author" content="SLART" />

<meta name="page-topic" content="SLART PHOTO" />

<meta name="description" content="Photos of the little mouse who always steals the cheese and the cat never catches." />

<meta name="keywords" content="Photo Cat Dog Mouse Cheese" />

<meta name="Generator" content="Slart" />

<base href="http://example.com/" />

<? $theme->start_combining("script,css") ?>
<title>
...

 
slart

Joined: 2013-11-11
Posts: 112
Posted: Mon, 2013-12-16 11:56

It would be nice if the Open Graph meta tags would not be generated in the module social share, but along with the regular meta tags to the page itself, or the theme.
If it is possible to draw up a simple solution to the image description truncated in the metatags description and og:description to take into it.

PS: I changed the Topic. I had a mistake. The description of the photos is called also description that I have confused with the meta tag description.

 
slart

Joined: 2013-11-11
Posts: 112
Posted: Mon, 2013-12-16 17:12

I found this, but no idea where I should put this.
http://www.the-art-of-web.com/php/truncate/
I like the option "2. Truncation at sentence breaks".

 
slart

Joined: 2013-11-11
Posts: 112
Posted: Thu, 2013-12-19 21:23

Hi Dave, you have no idea?

 
slart

Joined: 2013-11-11
Posts: 112
Posted: Fri, 2013-12-20 08:45

Wow! I am pleasantly surprised and happy! I've manage it myself.
I have the whole Gallery3:Modules list read but the Modules:metadescription overlooked. sorry.

Step by step.

- install and activate Module:social share
- 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

move, change and adapt.

/modules/metadescription/views/metadescription_block.html.php

at the end

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

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

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

<meta name="author" content="The name of the author" />

<meta name="Generator" content="The name of the generator" />

<base href="http://example.com/" />

You can insert here more meta tags if you wish.

You can determine the length of the characters of the description here.

Quote:
// Limit Description to 150 characters.

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

If a Facebook Like is not enabled, then this change yet.
/modules/social_share/helpers/social_share_theme.php

make a _ in this lines, and deactivate it. Facebook is your side no longer angry. (see debugger)

Quote:
<meta property=\"fb:app_id_\" content=\"$appId\"/>

<meta property=\"fb:admins_\" content=\"$adminId\"/>";

Use the Facebook Debugger to your pages in Facebook reread. Facbook has a cache.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Fri, 2013-12-20 21:18

Great! Glad you got it sorted and posted back for the community as well.

Cheers!
Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
MarkRH

Joined: 2007-05-25
Posts: 241
Posted: Sun, 2014-01-05 12:18

FYI, I put the following function in my local.php to truncate the description if it's too long:

function meta_description($description)
{ // BEGIN function meta_description
   $description = strip_tags($description);
   $description = str_replace('"','',$description);
   $max_length = 150;
   if (strlen($description) > $max_length) {
      $description = substr($description,0,$max_length ) . '...';      
   }
   return $description;
} // END function meta_description

Think I added the quote replacement because if I didn't it would cause a problem

Then in my theme's page.html.php file I have:

   <meta name="description" content="<? echo meta_description($theme->item()->description);  ?>" />
   <meta property="og:description" content="<?= meta_description($theme->item()->description) ?>" />

I have that Social Share module but either the version I have doesn't output the description information or I took it out LOL.
- Mark H.

Using Gallery 3.0.9 - gallery.markheadrick.com