Jump to content

Set title depending on page URL


Lek

Recommended Posts

Hi, I just read this old thread: https://forum.whmcs.com/showthread.php?101427-Set-title-of-page-using-an-action-hook

So I would like to have different title for each given cart page. For example a different title to cart.php?gid=3 and another title to cart.php?gid=6.

Is this syntax correct?

 <?php

function hook_setpagetitle($vars){

$pagetitle = "Set Page Title Here";

// also you can set title per page URL
if ($vars['contact.php']=='contacttitle'){
   $pagetitle = "Contact us now";
}
elseif ($vars['cart.php?gid=6']=='carttitle'){
   $pagetitle = "Email services";
}

return array("pagetitle" => $pagetitle);
}
add_hook("ClientAreaPage", 1, "hook_setpagetitle");

?> 

And should i remove

$pagetitle = "Set Page Title Here";

?

Thank you to everybody

Link to comment
Share on other sites

Lek,

 

I think you deviated too far from sentq's original code - something like the following should work...

 

<?php

function hook_setpagetitle($vars){

// also you can set title per page URL
   if ($vars['filename']=='index'){
       $pagetitle = "Home Page";
   }
   elseif ($vars['filename']=='cart' && $vars['gid']){
       $pagetitle = $vars['groupname'];
   }
   elseif ($vars['filename']=='contact'){
       $pagetitle = "Contact us now";
   }
   if ($pagetitle) {
       return array("pagetitle" => $pagetitle);
   }
}
add_hook("ClientAreaPage", 1, "hook_setpagetitle");

?>

when in the cart, it should automatically show the Product Group Name for each group - so that should remove the need to add each group manually to your hook code! :idea:

you should be able to work your way through all steps of the cart using the existing variables - $templatefile should be useful for the remaining cart steps, but you may need to use other variables too.

 

i'd be inclined to remove the "Set Page Title Here" line and let WHMCS use it's own default title for pages you haven't specified... the above hook will only change the pagetitle if the conditions specified in the hook are met; if they aren't, then the hook doesn't make any changes and WHMCS will use what it normally uses for each page. :idea:

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated