Wordpress - "php if in_title"

egomOnia

Registered Member
Joined
Oct 21, 2009
Messages
92
Reaction score
62
Is there some way to check if there's a certain keyword in a wordpress post title?

According to the wordpress codex, there are functions like is_category, in_category or has_tags to check if a post is in a certain category or uses specific tags.

But I need something like an "in_title" function to check if there is a certain keyword in the post title in order to display highly relevant ads.

Does anyone know a way to do this?
 
you'll have to play a bit with wp_title and PHP's strpos

Code:
http://codex.wordpress.org/Template_Tags/wp_title
Code:
http://www.php.net/manual/en/function.strpos.php

assembly required
 
This works, although I'm not the most advanced coder so there may be a more efficient way of scripting this:

PHP:
<?php

$title = get_the_title();

$keyworda = 'ppc';
$keywordb = 'ppv';
$keywordc = 'cpa';

if(stristr($title,$keyworda)){

 //show banner for ppc?

}
elseif(stristr($title,$keywordb)){

 //show banner for ppv?

}
elseif(stristr($title,$keywordc)){

 //show banner for cpa?

}
else {

 //show a generic banner

}
?>

This code must be place within the loop.
 
I'm going to test it immediately and report the results. Thanks in advance for your efforts!
 
Thanks, works exactly the way I wanted it to work!
 
Back
Top