Firefox PHP

Phorum data in meta description and title

Posted by Brian Moon 
Phorum data in meta description and title
September 24, 2005 08:03AM
Update: The code was messing up titles on pages that used the message template.

I have added a little text to my headers here at phorum.org to optimize the title and meta description tag in Phorum. While I can't say it helped Google, search results for our site look better on Google for sure. We had the same meta on all pages before. Not sure if this will help on a page that has no meta tags or not.
<?php

// defaults for all Phorum pages
$TITLE = $PHORUM["DATA"]["HTML_TITLE"];
$DESCRIPTION = "Your page default meta description should go here.";

if(isset($PHORUM["DATA"]["MESSAGE"]) && is_array($PHORUM["DATA"]["MESSAGE"])){

    // title and meta for read pages
    $TITLE = htmlspecialchars($PHORUM["DATA"]["MESSAGE"]["subject"]);
    $DESCRIPTION = htmlspecialchars(preg_replace('!\s+!s'," ",strip_tags(substr($PHORUM["DATA"]["MESSAGE"]["body"],0,300))));

} elseif(isset($PHORUM["description"]) && phorum_page=="list" && $PHORUM["DATA"]["CURRENTPAGE"]==1){

    // title and meta for list pages
    $TITLE = $PHORUM["name"];
    $DESCRIPTION = htmlspecialchars(preg_replace('!\s+!s', " ", strip_tags($PHORUM["description"])));
}
?>
<title><?=$TITLE?></title>
<meta name="description" content="<?=$DESCRIPTION?>" />

See: [www.google.com] for how it looks in Google with this in use on read pages.

Brian - Cowboy Ninja Coder - Personal Blog - Twitter



Edited 4 time(s). Last edit at 03/01/2006 06:40PM by brianlmoon.
Re: Phorum data in meta description and title
September 24, 2005 05:10PM
Is it suppose to strip everything in message body even the spaces between words?

It works but in the description the message body are completely stripped including the spaces between the words ..

Example.

In Message body:

It is printed in bold white letters on a Royal Blue background with the "State of Louisiana" seal in gold.


In Meta Description:

ItisprintedinboldwhitelettersonaRoyalBluebackgroundwiththe"StateofLouisiana"sealingold



Thanks
Bill


Re: Phorum data in meta description and title
September 24, 2005 07:08PM
preg_replace('!\s+!s', "", ....

should be

preg_replace('!\s+!s', " ", ....

And maybe it's wise to add

$DESCRIPTION = htmlspecialchars($DESCRIPTION);

to quote quotes that might be in the description string.
Re: Phorum data in meta description and title
September 24, 2005 07:09PM
With the help from Tiorthan on irc chat server, he pointed out that both lines

$DESCRIPTION = preg_replace('!\s+!s', "", strip_tags

needed space between the two quotes




It should be like this

$DESCRIPTION = preg_replace('!\s+!s', " ", strip_tags


Thank you Tiorthan and it worked!



CBiLL


Re: Phorum data in meta description and title
September 25, 2005 10:24PM
I changed the original post. Sorry about that. It was not an exact copy and paste from my code as mine is in my site header, not the template header.

Brian - Cowboy Ninja Coder - Personal Blog - Twitter
Re: Phorum data in meta description and title
October 06, 2005 02:34PM
I allows smileys on my forum subject line so any time anyone use a smiley in the sujbect line it would show the actual smileys html tags in the title so here my version of the php meta tag which is same as Brain but changed slightly to strip the html codes from the title.

--change--

// title and meta for read pages
$TITLE = htmlspecialchars($PHORUM["DATA"]["MESSAGE"]["subject"]);

--to--

// title and meta for read pages
$TITLE = htmlspecialchars(preg_replace('!\s+!s', " ", strip_tags($PHORUM["DATA"]["MESSAGE"]["subject"])));









--change--

// title and meta for list pages
$TITLE = $PHORUM["name"];


--to--


// title and meta for list pages
$TITLE = preg_replace('!\s+!s', " ", strip_tags($PHORUM["name"]));






Bill
Re: Phorum data in meta description and title
November 25, 2005 08:11AM
I don't think it is advisable to have some pages contain large (1000s of characters) meta descriptions, which unless I am missing something the code above will allow. Even avoiding getting into a SEO debate, it is still IMHO a waste of bandwidth.

I'd suggest something like:

$DESCRIPTION = htmlspecialchars(preg_replace('!\s+!s'," ",strip_tags(substr($PHORUM["DATA"]["MESSAGE"]["body"],0,500))));

This will truncate your page description to 500 characters - chop and change based on your SEO preferences.

/\dam

--
My notable Phorum sites:
Movie Deaths Database - "review comments" system mostly powered by Phorum
Learn Chinese! - integrated forum quiz
Re: Phorum data in meta description and title
December 20, 2005 11:10AM
Quote
sheik
I don't think it is advisable to have some pages contain large (1000s of characters) meta descriptions, which unless I am missing something the code above will allow. Even avoiding getting into a SEO debate, it is still IMHO a waste of bandwidth.

I'd suggest something like:

$DESCRIPTION = htmlspecialchars(preg_replace('!\s+!s'," ",strip_tags(substr($PHORUM["DATA"]["MESSAGE"]["body"],0,500))));

This will truncate your page description to 500 characters - chop and change based on your SEO preferences.

/\dam

This is exact the same what I also thought about it. 200 letters should be maximum.

If you look in the HTML-Source of Brian's first posting [phorum.org] , you also see how much (too much) text there is.

bye
irob
Re: Phorum data in meta description and title
December 20, 2005 12:43PM
You are right. I comprimised and went with 300.

Brian - Cowboy Ninja Coder - Personal Blog - Twitter
Re: Phorum data in meta description and title
December 21, 2005 07:12AM
hi,

Quote
sheik

$DESCRIPTION = htmlspecialchars(preg_replace('!\s+!s'," ",strip_tags(substr($PHORUM["DATA"]["MESSAGE"]["body"],0,500))));

This will truncate your page description to 500 characters - chop and change based on your SEO preferences.

What exactly must I write, if I want the "cut" text after a [ENTER]-sign (<br>) instead of a cut after 500 letters? Thank you.

bye,
irob
Sorry, only registered users may post in this forum.

Click here to login