Drupal nodewords token does not work for all metadata | Custom token
Published by Nicholas Dunbar on December 24th, 2012
For Drupal 6
You installed nodewords and there is no token for any of the meta data except for metatags-description. What if you want a metatags-keywords or a metatags-abstract or any of the following:
Canonical URL
Copyright
Description
Keywords
Revisit after
Robots
Location
Short URL
and any of the others that are avialable under the nodewords module?
Here is how I fixed it:
1.) I downloaded http://drupal.org/project/token_custom
and installed this module into my drupal 6
2.) I then went to site building > tokens and added a token called
token_custom_keywords
3.) in the PHP replacement field I put the following code:
echo $object- > nodewords['metatags']['keywords']['value'];
Now I have a custom token for the nodewords metatag keywords
If you want to do any other metatags from nodewords you can see what is available by printing the object
print_r($object- > nodewords);
and you will see all the different meta tags that are available.
make sure that you have enabled all the types you want in nodewords first.
Note if you do
print_r(get_defined_vars());
you will get a list of what is avialable in the scope that you can use for your custom token. I did this in the page title module and I got something like this:
Array
(
[code] = > $arr = get_defined_vars();
$keywords = "";
function find_keywords($item, $key)
{
if (strtolower($key) == "keywords"){
$keywords = $item;
}
//echo $key."\n";
}
array_walk_recursive($arr, 'find_keywords');
//echo $keywords;
print_r($arr);
[type] = > node
[object] = > stdClass Object
(
[nid] = > 3
[type] = > moderated
[language] = >
[uid] = > 1
[status] = > 1
[created] = > 1298522967
[changed] = > 1304722482
[comment] = > 2
[promote] = > 0
[moderate] = > 0
[sticky] = > 0
[tnid] = > 0
[translate] = > 0
[vid] = > 29
[revision_uid] = > 1
[title] = > Organizations
[body] = >
[log] = > needed meta tags and a summary
[revision_timestamp] = > 1304722482
[format] = > 1
[name] = > admin
[picture] = >
[data] = > a:1:{s:13:"form_build_id";s:37:"form-d9f36beaffed2413fa83b23323efa12c";}
[path] = > content/organizations
[revision_moderation] = > 1
[last_comment_timestamp] = > 1298522967
[last_comment_name] = >
[comment_count] = > 0
[taxonomy] = > Array
(
)
[page_title] = >
[nodewords] = > Array
(
[metatags] = > Array
(
[description] = > Array
(
[value] = > How to fix the stress related trauma in your organization
)
[keywords] = > Array
(
[value] = > trauma, business, drama, rationality, backstabbing
)
)
)
[nodewords_nodetype_override] = >
[build_mode] = > 0
[readmore] = > 1
[content] = > Array
(
[#suffix] = >
[#prefix] = >
[body] = > Array
(
[#weight] = > 0
[#value] = >
[#title] = >
[#description] = >
[#printed] = > 1
)
[#title] = >
[#description] = >
[#children] = >
[#printed] = > 1
)
[links] = > Array
(
)
)
[node] = > stdClass Object
(
[nid] = > 3
[type] = > moderated
[language] = >
[uid] = > 1
[status] = > 1
[created] = > 1298522967
[changed] = > 1304722482
[comment] = > 2
[promote] = > 0
[moderate] = > 0
[sticky] = > 0
[tnid] = > 0
[translate] = > 0
[vid] = > 29
[revision_uid] = > 1
[title] = > Organizations
[body] = >
[log] = > needed meta tags and a summary
[revision_timestamp] = > 1304722482
[format] = > 1
[name] = > admin
[picture] = >
[data] = > a:1:{s:13:"form_build_id";s:37:"form-d9f36beaffed2413fa83b23323efa12c";}
[path] = > content/organizations
[revision_moderation] = > 1
[last_comment_timestamp] = > 1298522967
[last_comment_name] = >
[comment_count] = > 0
[taxonomy] = > Array
(
)
[page_title] = >
[nodewords] = > Array
(
[metatags] = > Array
(
[description] = > Array
(
[value] = > How to fix the stress related trauma in your organization
)
[keywords] = > Array
(
[value] = > trauma, business, drama, rationality, backstabbing
)
)
)
[nodewords_nodetype_override] = >
[build_mode] = > 0
[readmore] = > 1
[content] = > Array
(
[#suffix] = >
[#prefix] = >
[body] = > Array
(
[#weight] = > 0
[#value] = >
[#title] = >
[#description] = >
[#printed] = > 1
)
[#title] = >
[#description] = >
[#children] = >
[#printed] = > 1
)
[links] = > Array
(
)
)
)