Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
How can I add custom description to threads?
Right now the description is same as title of page. I want to modify the way description is generated. The description meta should pull first 2-3 lines from post content on single page or there should be a meta box above post editor to write a custom description or summary.
0
Best Answer
-
sahotataran ✭✭✭
open
/plugins/VanillaSEO/class.vanillaseo.plugin.php and replacepublic function DiscussionController_Render_Before ( $Sender ) { if ( !$this->Enabled() ) return; $tags = array(); // Check if we have tags from current discussion. if ( C('Plugins.Tagging.Enabled') && isset($Sender->Discussion->Tags) ) { $tags += explode(' ', $Sender->Discussion->Tags); } // Calculate Page for Single discussion. /* * No need for calculating pages since we aren't doing titles for multiple pages. $Offset = (int) $Sender->Offset; $Limit = (int) C('Vanilla.Comments.PerPage', 50); $page = (int) PageNumber($Offset, $Limit); if ( $page <= 0 ) $page = 1; */ array_walk($tags, 'strip_tags'); array_walk($tags, 'trim'); array_walk($tags, 'htmlspecialchars'); $tags = array_unique($tags); if ( count($tags) > 0 ) { $Sender->Head->AddTag('meta', array('name' => 'keywords', 'content' => implode(', ', $tags))); } $Sender->Head->AddTag('meta', array('name' => 'description', 'content'=> $Sender->Discussion->Name)); $data = array ( 'title' => $Sender->Discussion->Name, 'category' => $Sender->Discussion->Category, ); $type = 'discussion_single'; $this->ParseTitle($Sender, $data, $type); }
with
public function DiscussionController_Render_Before ( $Sender ) { if ( !$this->Enabled() ) return; $tags = array(); // Check if we have tags from current discussion. if ( C('Plugins.Tagging.Enabled') && isset($Sender->Discussion->Tags) ) { $tags += explode(' ', $Sender->Discussion->Tags); } // Calculate Page for Single discussion. /* * No need for calculating pages since we aren't doing titles for multiple pages. $Offset = (int) $Sender->Offset; $Limit = (int) C('Vanilla.Comments.PerPage', 50); $page = (int) PageNumber($Offset, $Limit); if ( $page <= 0 ) $page = 1; */ array_walk($tags, 'strip_tags'); array_walk($tags, 'trim'); array_walk($tags, 'htmlspecialchars'); $tags = array_unique($tags); if ( count($tags) > 0 ) { $Sender->Head->AddTag('meta', array('name' => 'keywords', 'content' => implode(', ', $tags))); } $MetaDescriptionlimit = 20; //number of words you want to display $Description = $Sender->Discussion->Body; $Description = explode(' ', strip_tags($Description)); $Description = array_slice($Description,0,$MetaDescriptionlimit); $Description = implode(' ',$Description); $Sender->Head->AddTag('meta', array('name' => 'description', 'content'=> $Description)); $data = array ( 'title' => $Sender->Discussion->Name, 'category' => $Sender->Discussion->Category, ); $type = 'discussion_single'; $this->ParseTitle($Sender, $data, $type); }
There was an error rendering this rich post.
0
Answers
This plugin might be what you want, or should at least give you an idea of how to do it.
http://vanillaforums.org/addon/discussionexcerpt2-plugin
I already have installed this plugin. But I am talking about meta description. It doesn't create a meta description.
try SeoCompanion
by customizing it a little bit - you can actually specify how much content you want to display in the meta description of your page for single Discussion.
There was an error rendering this rich post.
@sahotataran
The problem with SeoCompanion is that it adds description to every page and the pages that don't have description, it will add pre-defined description to the page. So there will be many pages on the forum with same title and description.
I only want description in threads or single post pages.
I am using vanilla SEO plugin and its ok for general use. But however it does not work with description.
TItle are generated according to the page you are viewing. They depend on category and individual discussion pages and then all discussion page - so they are all different!
its just about meta description which can be same - not a big deal - else in SeoCompanion plugin you can specify meta description for individual pages(category and all discussions) and for single discussion pages!
There was an error rendering this rich post.
Duplicate meta description can't be same for more than one page. Every page should have different title and meta description. If you have two pages with same meta description, google will treat it as duplicate description.
In single post page, the default description is the page title. I want to change the description from page title to first 1-2 lines from content itself.
It shouldn't be a big deal, but I don't know PHP and especially I am a vanilla noob..
open
/plugins/VanillaSEO/class.vanillaseo.plugin.php and replace
with
There was an error rendering this rich post.
@sahotataran thanks for the code. The code changes from line 30 only.. So I think I should replace the bottom few lines only..
As I can recognize, the snippet is of SEO companion plugin so won't it create messup coz the syntex of the two plugins is different?
Have you tested it before because my site is live and submitted to search engines and it won't be a good idea to test on a live site.
i did test it out. it wont conflict with anything either. code is the same and the concept is same. it just where and how you implement it! thanks
There was an error rendering this rich post.
hello
vanilla roxx
neet ug pg ss official site