A Content block for the description meta tag

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

A Content block for the description meta tag

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
codecop
New Member
New Member
Posts: 9
Joined: Wed Sep 19, 2007 12:56 pm

Re: A Content block for the description meta tag

Post 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  ???
reneh
Dev Team Member
Dev Team Member
Posts: 446
Joined: Tue Nov 28, 2006 8:39 pm
Location: Norway

Re: A Content block for the description meta tag

Post 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.
ReneH 8-)
A search will save you hours waiting for an answer! Image
Jack @ PharSide

Re: A Content block for the description meta tag

Post 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
Pierre M.

Re: A Content block for the description meta tag

Post 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
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm
Location: Comox Valley, BC

Re: A Content block for the description meta tag

Post by Nullig »

@Jack

Have you tried adding

oneline='true'

to the tag?

Nullig
hexdj
Power Poster
Power Poster
Posts: 415
Joined: Sat Mar 24, 2007 8:28 am

Re: A Content block for the description meta tag

Post by hexdj »

Great tip! gonna use right away!
User avatar
meiriem
New Member
New Member
Posts: 5
Joined: Wed Apr 23, 2008 10:25 am
Location: Utrecht, Netherlands

Re: A Content block for the description meta tag

Post 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;
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: A Content block for the description meta tag

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
webguide
Forum Members
Forum Members
Posts: 15
Joined: Fri Feb 29, 2008 9:40 am

Re: A Content block for the description meta tag

Post 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?
webguide
Forum Members
Forum Members
Posts: 15
Joined: Fri Feb 29, 2008 9:40 am

Re: A Content block for the description meta tag

Post 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.
JeremyBASS

Re: A Content block for the description meta tag

Post 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
Last edited by JeremyBASS on Sat Jul 26, 2008 7:59 am, edited 1 time in total.
Marijus

Re: A Content block for the description meta tag

Post 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.
Peciura

Re: A Content block for the description meta tag

Post 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).
Marijus

Re: A Content block for the description meta tag

Post by Marijus »

It seems that I did everything as shown, but still does not working for me.
Post Reply

Return to “Tips and Tricks”