Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2010-07-04 16:37:00
- joel
- Member
- Registered: 2004-11-26
- Posts: 162
Best practises with custom meta information
Hi,
I’ve looked around to get my mind clear about this.
What I need is the possibility to change the Page Title and Meta Description via custom fields for some articles.
If that’s is not possible, Is there a way of doing it “manually” for a number of articles via conditionals in the head-section? For instance <txp:if_article_id….
Please point me in the right direction.
I’ve tride the Rah_metas plugin but I couldn’t make it perform something like this.
Thanks a lot in advance! :)
Offline
Re: Best practises with custom meta information
<title><txp:if_individual_article>
<txp:if_custom_field name="custom_title">
<txp:custom_field name="custom_title" />
<txp:else />
<txp:page_title />
</txp:if_custom_field>
<txp:else />
<txp:page_title />
</txp:if_individual_article></title>
Something similar would work for the meta description.
Code is topiary
Offline
#3 2010-07-04 17:53:53
- joel
- Member
- Registered: 2004-11-26
- Posts: 162
Re: Best practises with custom meta information
Thanks for your instant reply. However, that doesn’t seem to work for me. But that is the kind of solution I’d prefer. I also tried to wrap the title attr in asy_wondertag tags. That didn’t work eiter.
Offline
#4 2010-07-04 18:00:01
- net-carver
- Archived Plugin Author
- Registered: 2006-03-08
- Posts: 1,648
Re: Best practises with custom meta information
joel
if you are using a recent version of TXP you don’t need asy_wondertags just use single quotes inside the tag attribute you wish to nest. What version of TXP are you using?
— Steve
Offline
#5 2010-07-04 18:14:36
- joel
- Member
- Registered: 2004-11-26
- Posts: 162
Re: Best practises with custom meta information
Ahh that’s good news! It’s the recent 4.2.0
Last edited by joel (2010-07-04 18:15:03)
Offline
Re: Best practises with custom meta information
joel wrote:
Thanks for your instant reply. However, that doesn’t seem to work for me. But that is the kind of solution I’d prefer. I also tried to wrap the title attr in asy_wondertag tags. That didn’t work eiter.
What title attribute? The title tags I included in my example are just HTML tags, not Txp tags.
Post a tag trace for more help. I haven’t actually tested the code I posted, but I think it should work.
Do you have a custom field named custom_title?
Hi Steve!
Code is topiary
Offline
#7 2010-07-04 18:41:54
- joel
- Member
- Registered: 2004-11-26
- Posts: 162
Re: Best practises with custom meta information
It was the html-tags I was referring to :)
Yes, I have the custom field name right.
Here is my code (exactly yours except for the field name):
<title><txp:if_individual_article>
<txp:if_custom_field name="meta-titel">
<txp:custom_field name="meta-titel" />
<txp:else />
<txp:page_title />
</txp:if_custom_field>
<txp:else />
<txp:page_title />
</txp:if_individual_article></title>
Last edited by joel (2010-07-04 18:43:07)
Offline
Re: Best practises with custom meta information
Just tested it and it worked as expected. What output are you getting? Can you post a tag trace or a link to one?
Code is topiary
Offline
#9 2010-07-04 18:55:08
- joel
- Member
- Registered: 2004-11-26
- Posts: 162
Re: Best practises with custom meta information
I deactivated some old plugins and than it suddenly works!!!
Thanks so much for your assistance!!! :)))
Last edited by joel (2010-07-04 18:55:22)
Offline
#10 2010-07-04 23:20:46
- GugUser
- Member

- From: Quito (Ecuador)
- Registered: 2007-12-16
- Posts: 1,477
Re: Best practises with custom meta information
I wrote about the same topic in the german forum
Offline
#11 2010-07-05 11:31:24
- joel
- Member
- Registered: 2004-11-26
- Posts: 162
Re: Best practises with custom meta information
Is this possible to assign to a single article on an article list page IE the “landing page”?
I would prefer not using “Sticky” articles
Last edited by joel (2010-07-05 12:12:41)
Offline
Re: Best practises with custom meta information
Create conditional logic for determining whether or not you’re on a landing page. soo_if_frontpage is one solution. Or you could use core tags, combing e.g. if_article_list, if_search, etc. as you need.
Not sure what output you’re after, but you can use article_custom and specify the article ID if you don’t want to use sticky articles.
Code is topiary
Offline
Re: Best practises with custom meta information
I use the following code for the dynamic parts of my meta info, pretty much covers all you’d need…
First, install etz_striptags plugin, then create custom fields ‘meta_title’, ‘meta_desc’ and ‘meta_robots’.
Put this code in your page template (or a ‘misc’ type form linked from the page template):
<txp:if_section name="">
<txp:if_status number="200">
<txp:article_custom section="homepage" status="sticky" form="meta_dynamic" />
</txp:if_status>
<txp:else />
<txp:if_individual_article>
<txp:article form="meta_dynamic" />
<txp:else />
<txp:article status="sticky" form="meta_dynamic" />
</txp:if_individual_article>
</txp:if_section>
What the code above does is pull in article info even if the page is a sticky or the homepage (for that you’ll need to set up a section called ‘homepage’ and a sticky article for it and make sure that section is set to display on homepage).
Then set up an ‘article’ type form with the following in it:
<title>
<txp:if_custom_field name="meta_title">
<txp:custom_field name="meta_title" />
<txp:else />
<txp:title />
</txp:if_custom_field>
| <txp:site_name /></title>
<txp:if_custom_field name="meta_desc"><meta name="description" content="<txp:custom_field name='meta_desc' />" />
<txp:else />
<meta name="description" content="<txp:etz_striptags><txp:excerpt /></txp:etz_striptags>" />
</txp:if_custom_field>
<txp:if_keywords>
<meta name="keywords" content="<txp:keywords />" />
<txp:else />
<meta name="keywords" content="your,default,keywords,here" />
</txp:if_keywords>
<txp:if_custom_field name="meta_robots">
<meta name="robots" content="<txp:custom_field name='meta_robots' />" />
<txp:else />
<meta name="robots" content="index,follow,noodp" />
</txp:if_custom_field>
<txp:if_section name="">
<txp:else />
<txp:if_individual_article>
<txp:else />
<link rel="canonical" href="http://www.yourdomain.com/<txp:section />" />
</txp:if_individual_article>
</txp:if_section>
So that code checks whether you have put a custom page title in ‘meta_title’ custom field, and if not uses the page title instead.
Then it checks whether you have put a custom description in ‘meta_desc’ and if not uses the page excerpt, which has all textile formatting stripped out using etz_striptags (you probably could go further and have a default description if the user has not filled in the excerpt by using <txp:if_excerpt> though you should encourage users to always fill out a unique description for each page for SEO anyway).
Next it checks whether the keywords field has been filled in, and if not uses a default selection of keywords.
It then uses an SEO recommended robots meta unless you override it by entering a custom instruction in ‘robots_meta’ custom field (for example you could use ‘none’ in the meta_robots custom field for any pages you did not want search engines to index).
Finally, another SEO recommendation, it makes sure section landing pages are canonical – which means search engines index only http://www.yourdomain.com/yoursection and not http://www.yourdomain.com/yoursection/ (note the extra trailing slash) as sometimes they might index both those URLs separately and dilute your search ranking.
Hope that helps,
Phil
Offline