Dynamic meta description tag generation fix

Register an Account
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 11-24-2006, 03:32 AM
creep's Avatar
New Pligger
 
Join Date: Nov 2006
Location: Milan, Italy
Posts: 11
Not sure if this is the right place, but since original truncate_content() function don't doing all necessary "truncate" and often outputs html meta description tag in wrong way i consider this a bug and would like to share my fix with the community:

Found truncate_content() function in /libs/link.php

PHP Code:
    function truncate_content(){
        
$TruncatedContent substr($this->content0StorySummary_ContentTruncate);
        if(
strlen($this->content) > StorySummary_ContentTruncate){$TruncatedContent .= "...";}
        return 
$TruncatedContent;
    } 
and replace it with this new one:

PHP Code:
    function truncate_content(){

        
$TruncatedContent htmlspecialchars($this->content);
        
$TruncatedContent preg_replace('/\s+/'' 'trim($TruncatedContent));

        if(
strlen($TruncatedContent) > StorySummary_ContentTruncate) {
        
// Set the replacement for the "string break" in the wordwrap function
        
$cutmarker "**cut_here**";
        
// Using wordwrap() to set the cutmarker
        // NOTE: wordwrap (PHP 4 >= 4.0.2, PHP 5)
        
$TruncatedContent wordwrap($TruncatedContentStorySummary_ContentTruncate$cutmarker);
        
$TruncatedContent explode($cutmarker$TruncatedContent);
        
$TruncatedContent $TruncatedContent[0] . "...";
        }
        return 
$TruncatedContent;
    } 
After this the meta description tag will be generated in right way.

Enjoy!

Last edited by creep; 11-24-2006 at 05:45 AM. Reason: simplification of function (removed strip_tags, it's already in story.php)
Reply With Quote
  #2 (permalink)  
Old 12-04-2006, 11:44 AM
Constant Pligger
 
Join Date: Oct 2006
Posts: 220
What's wrong with the current output of the description meta tag?
Reply With Quote
  #3 (permalink)  
Old 03-17-2007, 11:32 AM
Casual Pligger
 
Join Date: Jan 2007
Posts: 68
If your story description has new lines, the description tag looks like:

Code:
<meta name="description" content="blabla

newline was there..." />
It should look like
Code:
<meta name="description" content="blabla &lt;br /&gt; &lt;br /&gt;newline was there..." />
Reply With Quote
Reply

Tags
description meta tag

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in Story Meta Description ffarhann Questions and Comments 3 01-26-2010 03:58 PM
Meta Description Problems HelloKitty Questions and Comments 1 11-24-2009 04:04 AM
Set Character Limit for Meta Description Tags? blaze Questions and Comments 2 04-08-2009 02:09 AM
How to set default description meta? tezzer Questions and Comments 5 10-04-2007 02:50 AM
Setting default meta description Biomech Questions and Comments 9 10-03-2007 02:08 PM


Pligg Modules and Pligg Templates from Pligg Pro Find support on the Pligg CMS Forum - 24 hours a day! Make a donation to support Pligg CMS development