SEO plugin: a simple idea
SEO plugin: a simple idea
Search engine look for meta tag, even if some say no. Specially, they look for meta description, may be just to show a short description in the result page.
I'm not able to write a plugin, now, but in my site I use this simple logic: I extract the first document paragraph and I use it a meta description and, for keywords, I extract all the words marked as bold (with b o strong tags). But one can use the em tag to identify the keywords or others.
This help to have meta information without write it in special field (which is time consuming)
It's simple to create such a plugin?
Satollo
I'm not able to write a plugin, now, but in my site I use this simple logic: I extract the first document paragraph and I use it a meta description and, for keywords, I extract all the words marked as bold (with b o strong tags). But one can use the em tag to identify the keywords or others.
This help to have meta information without write it in special field (which is time consuming)
It's simple to create such a plugin?
Satollo
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: SEO plugin: a simple idea
Hi!
I could write you such a plugin, if you give me your current code you use to extract the metafields!
Best regards,
Garvin
I could write you such a plugin, if you give me your current code you use to extract the metafields!
Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Re: SEO plugin: a simple idea
To extract the description this is a piece of code (very simple):
function extract_description($text)
{
$x = strpos($text, '<p>');
if ($x === false) return '';
$y = strpos($text, '</p>');
if ($y === false) return '';
$title = substr($text, $x+3, $y-($x+3));
$title = strip_tags($title);
return $title;
}
this is the code I use in my custom CMS. For the keywords:
function extract_keywords($text)
{
preg_match_all('/<strong>([^>]*)<\/strong>/si', $text, $match);
preg_match_all('/<b>([^>]*)<\/b>/si', $text, $match2);
return array_merge($match[1], $match2[1]);
}
this one return an array with all the "pieces of text" within b or strong tag. It's not perfect because it doesn't conseder tags with class or others attributes, but can be improved.
To join the keywords:
$keywords = join(",", extract_keywords($text));
code that can be added to the prevous function. Probably is better to apply an "strip_tags" to each keyword.
Satollo
function extract_description($text)
{
$x = strpos($text, '<p>');
if ($x === false) return '';
$y = strpos($text, '</p>');
if ($y === false) return '';
$title = substr($text, $x+3, $y-($x+3));
$title = strip_tags($title);
return $title;
}
this is the code I use in my custom CMS. For the keywords:
function extract_keywords($text)
{
preg_match_all('/<strong>([^>]*)<\/strong>/si', $text, $match);
preg_match_all('/<b>([^>]*)<\/b>/si', $text, $match2);
return array_merge($match[1], $match2[1]);
}
this one return an array with all the "pieces of text" within b or strong tag. It's not perfect because it doesn't conseder tags with class or others attributes, but can be improved.
To join the keywords:
$keywords = join(",", extract_keywords($text));
code that can be added to the prevous function. Probably is better to apply an "strip_tags" to each keyword.
Satollo
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: SEO plugin: a simple idea
Hi!
Great, that's a good suggestion. I just built a plugin to do this. It also allows you to define meta-tags per entry, and only if those are not set it will fetch them using your functions.
Have a try:
http://nopaste.php-q.net/223644
It's a lot more complex because of those overriding meta-tags per entry. if that wasn't required, the plugin would be reduced to half the size.
Best regards
Garvin
Great, that's a good suggestion. I just built a plugin to do this. It also allows you to define meta-tags per entry, and only if those are not set it will fetch them using your functions.
Have a try:
http://nopaste.php-q.net/223644
It's a lot more complex because of those overriding meta-tags per entry. if that wasn't required, the plugin would be reduced to half the size.
Best regards
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
-
Harald Weingaertner
- Regular
- Posts: 474
- Joined: Mon Mar 27, 2006 12:32 am
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Hi!
Sure, it got committed to Spartacus and will be there in a few days. I'll also announce it on the blog.
Regards,
Garvin
Sure, it got committed to Spartacus and will be there in a few days. I'll also announce it on the blog.
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Re: SEO plugin: a simple idea
It works great!
Now we can add some configuration, like the maximum number of characters/words to use for a description, or the html tags to use to identify the keywords, and so on!
Thank you very much!
By Satollo.
Now we can add some configuration, like the maximum number of characters/words to use for a description, or the html tags to use to identify the keywords, and so on!
Thank you very much!
By Satollo.
Re: SEO plugin: a simple idea
Just a note: I get this warning:
Warning: implode(): Bad arguments. in /home/mhd-01/www.naturalmentedonna.com/htdocs/diario ... tadesc.php on line 154
only on blog index (http://www.naturalmentedonna.com/diario). Can you check it?
Thank you, Satollo!
Warning: implode(): Bad arguments. in /home/mhd-01/www.naturalmentedonna.com/htdocs/diario ... tadesc.php on line 154
only on blog index (http://www.naturalmentedonna.com/diario). Can you check it?
Thank you, Satollo!
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: SEO plugin: a simple idea
Hi!
The foreach bug I fixed here:
http://nopaste.php-q.net/223670
For the configuration: Maybe you can help me there? You could modify the code to use substitution placeholders and then I tell how you to make them configurable.
Best regards,
Garvin
The foreach bug I fixed here:
http://nopaste.php-q.net/223670
For the configuration: Maybe you can help me there? You could modify the code to use substitution placeholders and then I tell how you to make them configurable.
Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Re: SEO plugin: a simple idea
ok, give me some time, i write down more generic functions. do i have to post them here?garvinhicking wrote:Hi!
The foreach bug I fixed here:
http://nopaste.php-q.net/223670
For the configuration: Maybe you can help me there? You could modify the code to use substitution placeholders and then I tell how you to make them configurable.
Best regards,
Garvin
Re: SEO plugin: a simple idea
Will that also be fixed for the spartacus?garvinhicking wrote:Hi!
The foreach bug I fixed here:
http://nopaste.php-q.net/223670
For the configuration: Maybe you can help me there? You could modify the code to use substitution placeholders and then I tell how you to make them configurable.
Best regards,
Garvin
Re: SEO plugin: a simple idea
This function
function extract_keywords($text, $tag_names="b,strong")
{
$tags = split(",", $tag_names);
$tags_count = count($tags);
$result = array();
for ($i=0; $i<$tags_count; $i++)
{
preg_match_all('/<' . $tags[$i] . '>([^>]*)<\/' . $tags[$i] . '>/si', $text, $match);
$results = array_merge($results, $match[1]);
}
return $results;
}
can be used to make the html tag to consider as a second parameter. I think it's easy to make the plugin configurable with a list of tag comma separated.
function extract_keywords($text, $tag_names="b,strong")
{
$tags = split(",", $tag_names);
$tags_count = count($tags);
$result = array();
for ($i=0; $i<$tags_count; $i++)
{
preg_match_all('/<' . $tags[$i] . '>([^>]*)<\/' . $tags[$i] . '>/si', $text, $match);
$results = array_merge($results, $match[1]);
}
return $results;
}
can be used to make the html tag to consider as a second parameter. I think it's easy to make the plugin configurable with a list of tag comma separated.
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: SEO plugin: a simple idea
Hi!
Thanks for that patch! I made it configurable and committed it to the plugin.
The new version will be found here in a few minutes:
http://php-blog.cvs.sourceforge.net/php ... t_metadesc
Best regards,
Garvin
Thanks for that patch! I made it configurable and committed it to the plugin.
The new version will be found here in a few minutes:
http://php-blog.cvs.sourceforge.net/php ... t_metadesc
Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
There is a small bug if you don't fill in any description or I have update the serendipity_event_metadesc.php file wrong.
bug:
Warning: implode(): Bad arguments. in /You/may/not/see this directory/html/plugins/serendipity_event_metadesc/serendipity_event_metadesc.php on line 109
Edit however I don't know that much of it (yet) but the problem is in this rule:
bug:
Warning: implode(): Bad arguments. in /You/may/not/see this directory/html/plugins/serendipity_event_metadesc/serendipity_event_metadesc.php on line 109
Edit however I don't know that much of it (yet) but the problem is in this rule:
Code: Select all
$meta_keywords = implode(',', $this->extract_keywords($GLOBALS['entry'][0]['body']));