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)
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by Raül Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
This can be done maybe a bit easier. You should extend all object/blog, object/file, etc views with your own view.
So in your plugin init function do:
In your view 'track_page_entity' you check if $vars["full_view"] = true. That means you have the "detail view" of a blog. If it is a full view, you can then save $vars["entity"] to a global $page_entity.
In you header extension, you can just check for the $page_entity and set the meta names...
I believe in Elgg 1.9 this is solved with more dynamic metanames provided by hooks.
dont forget to use elgg_get_excerpt($entity->description). Otherwise you could mess up your page
Thanks Jeroen. By saving $vars["entity"] to a global $page_entity you mean $CONFIG ?
No; you can declare a global variable like this:
in your tracking view:
in your header extension view:
I tried that, but I still seem to have the same principal problem with blog. $vars["entity"] returns empty.
@gerard then you must be doing something wrong... can you verify there is a $vars["entity"] in your 'tracking view'. Maybe you are extending the wrong view...
I am extending object/blog with a new view in the plugin. If I var_dump($my_page_entity) or $vars[entity'] it returns NULL. But only for blogs ! I (already) was able to extraxt entity information from pages, files, bookmarks, profiles. Even tried a fresh 1.8.16 install, same result. You are right, I must be doing something wrong :-) but don't know what. Have you tried that code with blogs ?
Maybe try to extend it before object/blog (with a priority lower than 500). This plugin does a similar trick: https://github.com/ColdTrick/entity_view_counter
Yes ! Works. Thank you Jeroen.
- Previous
- 1
- 2
- Next
You must log in to post replies.