Extend header

I am trying to extend the header with an excerpt to be put in meta description tag. Title and tags are not an issue to manipulate, but description is bugging me.

Whatever I try, it does not display. It works for users, just echo $user->description but for objects like blogs it does not seem to work.

This is the simple code snippet :

$article = $vars['entity'];

$description = elgg_get_excerpt($article->description, 170);

      ?>

<meta name="description" content="<?php echo $description;?>" />

Dynamic descriptions are valueable to search engines. Most of the time they take over what you provide here so it is important that the text is what the users wants to communicate. This normally is what they provide as excerpt.

 

Ps: var_dump $description says string(0) bool(false)

 

  • What does var_dump($vars['entity']) say?  I don't believe object entities are passed to the head view.

  • Hi Matt, I've read that you joined the team. Great !

    Var dump says "string(0) bool(false)"

     

  • Thanks!

    That's what I thought, the blog (or whatever it is) entity isn't being passed to the head view.  You'll either have to pass it in somehow or try to get it from inside that view.

  • Yes, it is possible to do it in the view but against the W3C guidelines. meta tags should be in the header. I am not sure if search engines will pick up meta tags in body.

    Is there a suitable workaround ? It is possible to read the XML and put it in the header (I tested that) but is very nasty and bad for performance since you have to read the whole page twice.

  • no, you're misunderstanding - I meant you'll have to pass the blog entity into the header view, or get the blog entity from within the header view.  Putting meta tags in the body would not be a good idea.

  • @Matt, I found it ! Thanks for pointing me in the right direction

  • ok good!

    Is it something that can be packaged into a plugin so other people can have nice meta tags? :)

  • Yes it does. But to be honest it is still complicated since there are many exceptions to handle. I am working on it and if above 90% on al content (with or without proper user, object, group, discussion description) I will put out a plugin for it.

  • I am about 60% now (files, pages, bookmarks, profies and some custom plugins) but I am still really stuck on blogs.

    I even tried  $entity = ($vars['entity']) ? ($vars['entity']) : (get_entity(get_input('entity_guid'))) to pull out entity information from a view that extends the head.

    There must be somebody how knows how to do this, or is it simply impossible to get blog excerpts or description from within the header ?