Users running a non-download version of Vanilla (pulled from github), on branch release/2019.016 or master from the last 2 weeks should upgrade to release/2019.017 or latest master for security reasons. Downloaded official open sources releases are not affected.

Generate Meta Desc from Post Content and Comment

This discussion is related to the Vanilla SEO addon.
edited December 2011 in Feedback

Change in function DiscussionController_Render_Before

from this:

`

    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->Data('Discussion.Name')));

    $data = array (
        'title' => $Sender->Data('Discussion.Name'),
        'category' => $Sender->Data('Discussion.Category'),
    );

    $type = 'discussion_single';        
    $this->ParseTitle($Sender, $data, $type);`

to this :

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)));
}

    $PageNum = ($Sender->Pager->Offset / $Sender->Pager->Limit) + 1;
    if($PageNum > 1){
    $CommentData = $Sender->Data('CommentData')->Result();
    $Description = strip_tags($CommentData[0]->Body);
    } else {
    $Description = strip_tags($Sender->Data('Discussion.Body'));
    }
    if(strlen($Description)<1){
        $Description = $Sender->Data('Discussion.Name');
    } else {
        $Description = explode(' ', $Description);
        $Description = array_slice($Description,0,40);
        $Description = implode(' ',$Description);
    }

    $Sender->Head->AddTag('meta', array('name' => 'description', 'content'=> $Description));

    $data = array (
        'title' => $Sender->Data('Discussion.Name').' - Page '.$PageNum.' ',
        'category' => $Sender->Data('Discussion.Category'),
    );

    $type = 'discussion_single';        
    $this->ParseTitle($Sender, $data, $type);</code>

Modify for :

  • Generate Meta Desc from Post Content

  • If not first page of Discussion will grab from first comment data in that page

  • Change to Title Tag to add Current Page Number of Discussion

hope, this will be useful for someone

Tagged:
Sign In or Register to comment.