right now, you’re testing for the GET variable, you can set a SESSION variable and test for that, which will carry through the site
I’m assuming that you have a function doing it, just do something like:
if ($_GET['kw']) {
$_SESSION['kw'] = $_GET['kw'];
}
if ($_SESSION['kw']) {
your title stuff goes here
}
Hi luckydragon,
Thanks for you help…
I am currently using:
if(trim($_GET['kw'])!=''){
$title=trim($_GET['kw']);
}
?>
But i can not get the title to follow through if users click through to different pages on the site.. :/
I tried using your code and it did the same..
Thanks,
Max
<?php
$title='- Compare prices and save up to 75%!';
$title='- Compare prices and save up to 75%!';
if(trim($_GET['kw'])!=''){
$title=trim($_GET['kw']);
}
?>
<h1><?php echo get_the_title($ID); ?> <?php echo $title; ?></h1>
This is the full peice of code i am using if this helps?
I don’t see my code anywhere..
if(trim($_GET['kw'])!=''){
$_SESSION['kw'] = $_GET['kw'];
}
if (trim($_SESSION['kw']) != '') {
$title=trim($_SESSION['kw']);
}
Ok I have changed it too..
<?php
$title='- Compare prices and save up to 75%!';
if(trim($_GET['kw'])!=''){
$_SESSION['kw'] = $_GET['kw'];
}
if (trim($_SESSION['kw']) != '') {
$title=trim($_SESSION['kw']);
}
?>
<h1><?php echo get_the_title($ID); ?> <? echo $_GET['kw'] ?></a></h1>
But its still now working :(. Would it be easier if i sent you a URL?
why are you putting this:
<? echo $_GET['kw'] ?> if you just assigned it to $title then why are you not using $title?
I do not know, I am really not very good with PHP and still trying to learn the basics. How would you configure this code?
change $_GET[‘kw’] to $title;
<h1><?php echo get_the_title($ID); ?> <? echo $title; ?></a></h1>
see if that helps
Nope it did not make any different 🙁
give me the url so I can see what it is doing.. then there might be another way to do it..
ok, let’s try it this way..
first off, delete the code you have now, and just have:
<h1><?php echo get_the_title($ID); ?></h1>
in your wp-config.php at the very top (on a line right after the <? and before the /*) put:
session_start();
then, in functions.php for your theme:
function my_set_new_title($title) {
global $wp_query;
if ($wp_query->query_vars['kw'] || $_GET['kw']) {
$_SESSION['kw'] = ($wp_query->query_vars['kw'] != "" ? $wp_query->query_vars['kw'] : $_GET['kw']);
}
if ($_SESSION['kw']) $title .= ' '.$_SESSION['kw'];
return $title;
}
add_filter('the_title','my_set_new_title');
Thank you so much, it works!
I have one problems though, it is adding the KW part of the titles too all links on the site. For example on the main navigation on the sidebar navigation etc..
Do you know a way to stop it appearing on here?
Thanks again for all your help, your a star!
yes, change this:
if ($_SESSION['kw']) $title .= ' '.$_SESSION['kw'];
to this:
if ($_SESSION['kw'] && in_the_loop()) $title .= ' '.$_SESSION['kw'];
Great it working for the main navigation – can we fix it for the navigation on the sidebar also?
You do not realize how much easier you have made my life today, thank you so much!