Page 1 of 2
A Content block for the description meta tag
Posted: Sun Nov 11, 2007 6:28 pm
by calguy1000
Here's a quick little trick I put together to easily create a meta description content block for each page.
Code: Select all
{content block='meta_description' wysiwyg='false' assign='meta_description'}
<meta name="description" content="{$meta_description|strip_tags|summarize:30:""}">
This will create a text area on each page that does not have a wysiwyg where you can type your 'descriptive sentence or two'.
and just incase you user tries to get smart with formatting, all tags are stripped
following that, the output is trimmed to 30 words, just incase the user types in way too much stuff.
Enhancements to this would be to create a smarty modifier that detected sentences, and trimmed it to two sentences, but that's not necessary at this time.
This tip also describes how to capture the contents of a content block into a smarty variable for processing, and how to combine smarty modifiers to accomplish various effects.
Re: A Content block for the description meta tag
Posted: Thu Nov 29, 2007 2:08 pm
by codecop
How to use this code?
if i place it in main template, or in some page meta data texarea, i got result:
without any text or so.. just spaces

Re: A Content block for the description meta tag
Posted: Sat Dec 01, 2007 1:03 pm
by reneh
Ohh I love that one Calguy1000!
Its a realy handy way to let the editors add the dexription for each page themself.
To codecop:
Of courxe just add these lines into the template in the header area. I.e. just below the other lines for metadata in you template.
Re: A Content block for the description meta tag
Posted: Sat Dec 15, 2007 3:40 pm
by Jack @ PharSide
Great tip Calguy. Worked perfectly and gave me some great ideas even though I was decent with smarty already. Thanks for that as always.
Here is a quick question, is there a tag you can use to change the size of the text area this tag produced? The box is currently pretty large. Not a huge deal but would be nice to know if possible.
Thx - J
Re: A Content block for the description meta tag
Posted: Sun Dec 16, 2007 12:03 pm
by Pierre M.
calguy1000 wrote:
This tip also describes how to capture the contents of a content block into a smarty variable for processing, and how to combine smarty modifiers to accomplish various effects.
Powerfull. Thank you for this tip.
Pierre
Re: A Content block for the description meta tag
Posted: Mon Dec 17, 2007 12:55 am
by Nullig
@Jack
Have you tried adding
oneline='true'
to the tag?
Nullig
Re: A Content block for the description meta tag
Posted: Wed Jan 16, 2008 3:26 am
by hexdj
Great tip! gonna use right away!
Re: A Content block for the description meta tag
Posted: Wed Apr 23, 2008 10:41 am
by meiriem
Another solution for the right meta description is to put at your Global Settings metadata the following:
Code: Select all
<meta name="description" content="{title} - {sitename} - {description}" />
(And of course put {metadata} in your template/page.)
Google wants that every page has a different description. By doing this you ensure that every page has an unique description.
{title} => the page title
{sitename} => the global sitename (optional)
{description} => the title attribute of the page (at tab "Options" when you edit the page)
@codecop
When you get just spaces then there is no content in content block='meta_description'.
@all
That summarize modifier is not correct. When you pass the suffix (e.g. "the end") it will be override by the default ("...").
Solution:
Code: Select all
in plugins/modifier.summarize.php change line 26:
//If set, the suffix (by default "...") will now be added to the summary ($returnstring)
$returnstring .= $etc;
Re: A Content block for the description meta tag
Posted: Thu Jun 05, 2008 3:18 pm
by calguy1000
In reply to meiriem's post, here's a solution that's the best of both worlds
(not tested yet but it should be close)
Code: Select all
{content block='meta_description' wysiwyg='false' assign='meta_description'}
{if empty($meta_description)}
{capture assign='meta_description'}{title} - {sitename} - {description}{/capture}
{/if}
<meta name="description" content="{$meta_description|strip_tags|summarize:30:""}">
This will provide a content area in the template, and theoretically, if it's empty, will use a combination of the sitename, title, and description fields. That way, authorized editors can optionally override the meta description field.
Re: A Content block for the description meta tag
Posted: Sat Jun 07, 2008 6:21 am
by webguide
calguy1000 wrote:
In reply to meiriem's post, here's a solution that's the best of both worlds
(not tested yet but it should be close)
Code: Select all
{content block='meta_description' wysiwyg='false' assign='meta_description'}
{if empty($meta_description)}
{capture assign='meta_description'}{title} - {sitename} - {description}{/capture}
{/if}
<meta name="description" content="{$meta_description|strip_tags|summarize:30:""}">
This will provide a content area in the template, and theoretically, if it's empty, will use a combination of the sitename, title, and description fields. That way, authorized editors can optionally override the meta description field.
How do you modify this so that, if the description field is empty it will take the first 30 or so words from the first text within in tags?
Re: A Content block for the description meta tag
Posted: Sun Jun 08, 2008 9:04 am
by webguide
webguide wrote:
calguy1000 wrote:
In reply to meiriem's post, here's a solution that's the best of both worlds
(not tested yet but it should be close)
Code: Select all
{content block='meta_description' wysiwyg='false' assign='meta_description'}
{if empty($meta_description)}
{capture assign='meta_description'}{title} - {sitename} - {description}{/capture}
{/if}
<meta name="description" content="{$meta_description|strip_tags|summarize:30:""}">
This will provide a content area in the template, and theoretically, if it's empty, will use a combination of the sitename, title, and description fields. That way, authorized editors can optionally override the meta description field.
How do you modify this so that, if the description field is empty it will take the first 30 or so words from the first text within in tags?
I solved it myself, I did like this:
Code: Select all
{content block='meta_description' wysiwyg='false' assign='meta_description'}
{if empty($meta_description)}
{capture assign='meta_description'}{title} - {sitename} - {content}{/capture}
{/if}
<meta name="description" content="{$meta_description|strip_tags|summarize:30:""}">
Its a bit "dirty" but this way I wont have to write descriptions, it takes the description from the actual content.
Re: A Content block for the description meta tag
Posted: Sat Jul 26, 2008 7:55 am
by JeremyBASS
Important FYI for those doing this nifty trick...
{description} can bring back code in cataloger (jquery code in my case)
where
{content} will redeclare functions
( I'd say the tag ie {blogs}) in blogs, and self registration
(that's all I found)...
I guess a work around is... um in the Page Specific Metadata:? not in the Global Metadata:
this is per
Self reg mod is not working..... any ideas?
I hope this save someone some time...
jeremyBass
Re: A Content block for the description meta tag
Posted: Mon Nov 08, 2010 1:57 pm
by Marijus
calguy1000 wrote:
Here's a quick little trick I put together to easily create a meta description content block for each page.
Code: Select all
{content block='meta_description' wysiwyg='false' assign='meta_description'}
<meta name="description" content="{$meta_description|strip_tags|summarize:30:""}">
This will create a text area on each page that does not have a wysiwyg where you can type your 'descriptive sentence or two'.
How to make such trick for news module.
Re: A Content block for the description meta tag
Posted: Tue Nov 09, 2010 2:48 am
by Peciura
http://calguy1000.com/Blogs/4/60/the-we ... dness.html
section "Meta Description Data for Detail Views"
You could create custom field for meta description value or use summary field (as described).
Re: A Content block for the description meta tag
Posted: Tue Nov 09, 2010 8:30 am
by Marijus
It seems that I did everything as shown, but still does not working for me.