Jump to content

Recommended Posts

I have several websites using the same basic script and I have the same problem in each - all the page titles are the same.

see

http://courseworkbank.info/?dir=GCSE

the page title here is COURSEWORKBANK.INFO

I would like it to be GCSE

For http://courseworkbank.info/?dir=GCSE/Biology

I would like it to be GCSE - Biology

How do I do this?

Am using a simple index.php file to load everything.

Link to comment
https://forums.phpfreaks.com/topic/294548-want-to-extract-page-title-from-url/
Share on other sites

Your structure seems to follow a pattern of '?dir=DIR1/DIR2/DIR3 etc, and you want to display a title of DIR1 - DIR2 - DIR3, the following code should suffice.

if ( isset( $_GET['dir'] ) )
{
  $explode = explode( '/', $_GET['dir'] );
  $dir_count = count( $explode );
  $title = '';
  $i = 1;

  foreach ( $explode as $k )
  {
    $suffix = ( $i == $dir_count ) ? '' : ' - '; // Seperate the directory names with -
    $title .= $k . $suffix;
    $i++;
  }
}

If you place this code before your title code (e.g. <title>COUR...</title>)

 

Then change your title code to <title><?= $title; ?></title>, it should work.

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.