Reply to comment

Content Type Field Alterations

After getting my must have modules installed I usually create or edit one of the default content types. Drupal lacks a meta description field which I feal is a must have for seo purposes. I'm not super worried about seo but it seems to me a that field is absolutely needed. (I skip the keywords field as its pretty much useless as far as I'm concerned)

The problem is after adding a meta description field through cck is that it will display it as a part of the entry instead of showing it in the proper header location (and telling fckeditor to exclude this field).

Two alterations are needed to make this work (I'm sure there are other ways as I have found but none yet good enough to make me do it that way instead of this way)

In page.tpl.php of my template I add this in the proper head area -

<meta name="description" content="<?php print check_plain($node->field_meta_description[0]['value'])?>" />

(I've run it through check_plain just in case any html has been entered as that will cause problems)

Now since I created a custom content type - default_article I copy node.tpl.php to node-default_article.tpl.php and replace

<?php print $content?>

with

<?php print $node->content['body']['#value']; ?>

as $content will containt the meta description that I do not want spit out as content.

Another step I could / probably will take is to check to see if a meta description was provided and if not use some of the first words from the body value just to make sure some description is available.

Check your permissions and make sure anonymous has view permissions for the field. Try logging out and viewing source to ensure that the tag is appearing as expected.

 

Reply

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
1 + 5 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.