WordPress.org

Ready to get started?Download WordPress

Forums

[closed] Title question (45 posts)

  1. maxthornton
    Member
    Posted 2 years ago #

    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

  2. luckdragon
    Member
    Posted 2 years ago #

    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
    }
  3. maxthornton
    Member
    Posted 2 years ago #

    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

  4. maxthornton
    Member
    Posted 2 years ago #

    <?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?

  5. luckdragon
    Member
    Posted 2 years ago #

    I don't see my code anywhere..

    if(trim($_GET['kw'])!=''){
    $_SESSION['kw'] = $_GET['kw'];
    }
    if (trim($_SESSION['kw']) != '') {
    	$title=trim($_SESSION['kw']);
    
    }
  6. maxthornton
    Member
    Posted 2 years ago #

    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?

  7. luckdragon
    Member
    Posted 2 years ago #

    why are you putting this:
    <? echo $_GET['kw'] ?> if you just assigned it to $title then why are you not using $title?

  8. maxthornton
    Member
    Posted 2 years ago #

    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?

  9. luckdragon
    Member
    Posted 2 years ago #

    change $_GET['kw'] to $title;

    <h1><?php echo get_the_title($ID); ?> <? echo $title; ?></a></h1>

    see if that helps

  10. maxthornton
    Member
    Posted 2 years ago #

    Nope it did not make any different :(

  11. luckdragon
    Member
    Posted 2 years ago #

    give me the url so I can see what it is doing.. then there might be another way to do it..

  12. maxthornton
    Member
    Posted 2 years ago #

    http://boilerreplacementuk.net/

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

  13. luckdragon
    Member
    Posted 2 years ago #

    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');
  14. maxthornton
    Member
    Posted 2 years ago #

    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!

  15. luckdragon
    Member
    Posted 2 years ago #

    yes, change this:
    if ($_SESSION['kw']) $title .= ' '.$_SESSION['kw'];
    to this:
    if ($_SESSION['kw'] && in_the_loop()) $title .= ' '.$_SESSION['kw'];

  16. maxthornton
    Member
    Posted 2 years ago #

    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!

  17. luckdragon
    Member
    Posted 2 years ago #

    hmmm... that in_the_loop() code should do that.. maybe change in_the_loop to is_single?

  18. maxthornton
    Member
    Posted 2 years ago #

    It kills the dynamic title all together of the site.. :/

  19. luckdragon
    Member
    Posted 2 years ago #

    or maybe is_page, but technically, in_the_loop should do that

  20. luckdragon
    Member
    Posted 2 years ago #

    is that menu a widget? or a custom menu? or what? how is it created?

  21. maxthornton
    Member
    Posted 2 years ago #

    is_page shows it everywhere again like it was before we put in in_the_loop..

    They created through the 'custom menu' option yes..

  22. luckdragon
    Member
    Posted 2 years ago #

    ok, let's try this then:

    <h1><?php global $bigtitle; $bigtitle = 1; echo get_the_title($ID); $bigtitle=0;?></h1>

    then in the function:
    global $wp_query,$bigtitle;
    and

    if ($_SESSION['kw'] && in_the_loop() && $bigtitle == 1) $title .= ' '.$_SESSION['kw'];
  23. maxthornton
    Member
    Posted 2 years ago #

    Ok done that, and still the same is showing :(..

    Do you think it is something that is going to be fixable? Or just one of those things that are unexplained and can't be fixed?

  24. luckdragon
    Member
    Posted 2 years ago #

    like I said, the in_the_loop() check should do it...

    I wonder..

    global $wp_query,$bigtitle,$mycount;
    
      $mycount++;

    then:

    if ($_SESSION['kw'] && in_the_loop()) $title .= ' '.$_SESSION['kw']." ".$mycount;

    check several pages, and see if the number that is after the title on the page is always the same..

    if it is, tell me the number please.

  25. maxthornton
    Member
    Posted 2 years ago #

    I added what you said, but no number shows after the title?

  26. luckdragon
    Member
    Posted 2 years ago #

    do this:
    instead of $mycount++ put:

    $mycount = ($mycount ? 0 : $mycount++);

    see if that helps

  27. maxthornton
    Member
    Posted 2 years ago #

    So replace$mycount++; with $mycount = ($mycount ? 0 : $mycount++);??

  28. luckdragon
    Member
    Posted 2 years ago #

    yes

  29. maxthornton
    Member
    Posted 2 years ago #

    Ok, done this and still nothing showing after the title.

    Could a plugin or something be knocking it out? or causing the problems?

  30. luckdragon
    Member
    Posted 2 years ago #

    no, how about this:

    instead of $mycount, use $bigtitle

    $bigtitle++;
    
    if ($_SESSION['kw'] && in_the_loop()) $title .= ' '.$_SESSION['kw']." ".$bigtitle;

Topic Closed

This topic has been closed to new replies.

About this Topic