WordPress.org

Support

Support » How-To and Troubleshooting » Title question

Title question

  • Hi,

    I was wondering if someone might be able to help me and answer a question of mine. I run a wordpress site as a lead generation website. I am using the ‘?kw=’ feature on my H1 titles so that I can target for the users that land on my site via paid search..

    I was wondering if there is a way that I can develop this title further so that the targeted title follow through the site for this specific user. For example a user searches on google ‘Double Glazing In Manchester’, the user will click one of my adds and the title will show Double Glazing Prices In Manchester.

    But as soon as they click onto another pages the title goes back to normal, is there any way using cookies or something similar I can make the title targeted throughout the site for users via paid search?

    Thanks,
    Max

Viewing 15 replies - 1 through 15 (of 44 total)
  • 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..

    http://boilerreplacementuk.net/

    An example of the ‘kw’ being used would be..
    http://boilerreplacementuk.net/?kw=In Manchester

    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!

Viewing 15 replies - 1 through 15 (of 44 total)
  • The topic ‘Title question’ is closed to new replies.