• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 342
  • Last Modified:

Auto meta tags for profile pages

I'm looking to have auto generated meta tags for profile pages based on a specific profile field e.g the brief description. is it possible to modify the nodewords module to do this as well as its usual function?
0
Lambo_OO
Asked:
Lambo_OO
  • 10
  • 6
1 Solution
 
RobertPopeCommented:
Can that be implemented in combination with the profile as content type module?  Another option is to check the variables available to your page using the devel module - then modifying your user tpl file in your theme to generate the node tags dynamically using those variables and leaving nodewords out of it entirely.

Hope this helps

Robert
0
 
Lambo_OOAuthor Commented:
I will have a look at leaving nodewords out of it and modifying the tpl.php. In the meantime, any snippets on what php to write to achieve the aim, gratefully received :-)
0
 
Lambo_OOAuthor Commented:
Have got so far with the solution. Putting following code into header will allow me to have custom meta tags for all user profiles.

What remains is being able to set the meta tags to a profile field e.g. for description use user->profile_description.

Thanks

 <?php
// If its is a user profile page
if (arg(0) == "user" && is_numeric(arg(1))) {
    $tags['description'] = "this is my custom meta description";
    $tags['keywords'] = "this is my custom meta keywords";

}
// All other pages
else {
    print '<meta name="keywords" content="" />';
    print '<meta name="description" content="" />';
}
?>
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Lambo_OOAuthor Commented:
apologies, this is the right code:

  <?php
// If its is a user profile page
if (arg(0) == "user" && is_numeric(arg(1))) {
    print '<meta name="keywords" content="profile" />';
    print '<meta name="description" content=profile" />';
}
// All other pages
else {
    print '<meta name="keywords" content="" />';
    print '<meta name="description" content="" />';
}
?>
0
 
RobertPopeCommented:
if you want to use elements on profile pages you will want to check out the $account rather than the node object...

Hopefully I will have time to answer more fully later
0
 
Lambo_OOAuthor Commented:
I will have  a look at using $account... but look forward to your full answer. Thanks
0
 
Lambo_OOAuthor Commented:
Almost there! Have created a custom user_profile.tpl.php and put the following code in (along with that needed to print all the profile fields).

Last problem I have now to finish off that the meta tags below are printed in the body so I need to find a way to get the custom user_profile.tpl.php to print them to the head section of the page. Any help putting this one to bed would be great. Thx


--user_profile.tpl.php--

<?php
   profile_load_profile($account);
  drupal_set_title($account->profile_orgname);

 // If its is a user profile page

  $upinfo = check_plain($account->profile_BriefDescription);
  $meta_tags['description'] = array('type' => 'name');
  $meta_tags['description']['content'] =  $upinfo ;

  $meta_tags_output  = '';

  foreach($meta_tags as $tag_name => $tag_data) {
  $meta_tags_output .= '<head><meta '. $tag_data['type']. '="'. $tag_name .'" content="'  . $upinfo .   '" /></head>'."\n" ;
  }
  $vars['meta_tags'] = $meta_tags_output;

  print $meta_tags_output;
0
 
RobertPopeCommented:
you may want to look at placing your code in a page.tpl file like   page-user.tpl.php   copy out the contents of what is it page.tpl now and put it in page-user.tpl.php - then add your code.  Clear the drupal cache and you should be home free

Hope that helps

Robert
0
 
Lambo_OOAuthor Commented:
I tried cutting and pasting to page-user but it appears when the code is there it no longer has access to the profile fields so the meta description is empty...
0
 
Lambo_OOAuthor Commented:
Managed to finish this off with your help Robert - thank you. I used a combination of the code above with the snippet below to allow access to the profile fields and pasted into the page-user.tpl.php :-)

Thank you for your help :-)

//allows access to profile fields by loading the user object explicity

$uid = $GLOBALS['user']->uid;
  $user = user_load(array('uid' => $uid));
0
 
RobertPopeCommented:
Hey - I'm glad you were able to make use of the global user object - YAY!  Sorry I wasn't able to devote more attention to the task.  I'm glad you were able to work it out.

FYI lullabot.com has a training series that will dramatically cut your time if you are going to be working with Drupal alot.  And of course if you need any help working on a project in the future, big or small for advice or to contract let me know :)

Robert Pope
Marliin CTO
www.marliin.com
0
 
RobertPopeCommented:
also global $user will make the current logged in user available to you as $user

Are you sure that the metatags showing up are for the appropriate profile based on the profile the logged in user is looking at rather than his own metatag info on all the user pages?
0
 
Lambo_OOAuthor Commented:
You're right Robert, the meta tags shown are only for when I am logged in and are only for my profile. When I am logged in the meta tags are from my profile and are on all user profile pages. If I log out the meta tags are empty for the profiles...

Any help?

Will definately have a look at lullabot.com thanks.
0
 
Lambo_OOAuthor Commented:
Finally put this one to bed by reseting the uid to the profile page and not the logged in user.
Regards
0
 
RobertPopeCommented:
Nice work - I was looking at how to do that before you found it - did you use arguments to reset it?
0
 
Lambo_OOAuthor Commented:
Yes i used following with above code and put this into the page-user.tpl.php:

 
  $uid = arg(1);
  $user = user_load(array('uid' => $uid));
  $upinfo = check_plain($user->profile_information);
  ...
  ...

  }

I just need to do some testing, primarily to what happens if I remove the meta tags by path from nodewords - will it try to create an automated meta tag for the desciption? Hopefully not, I think it doesnt create them if they are already set. Then I can upload. Regards
 
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 10
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now