Generate unique title tag from PHP page using H1 on the page?

I have a photo gallery archive that is generated using 1 single PHP file. The page code is all shared, and then I use and if/else if to generate the page based on what URL I type in. Each section has a unique H1 tag, but the title part of the page is shared. Is it possible to script this so that the H1 is pulled from the page and populated in the title field? I want this to be SEO friendly as possible. I’ve already made it so that the URL is friendly. Right now the best I could find was a script that changes the title for the viewer to use the H1 tag, but that is only ‘visual’ and doesnt actually change the title tag for search engines.

Here’s a sample page:
http://www.jeditemplearchives.com/vintagecollection/evg/025-R2-D2-The-Vintage-Collection-VC25.html

I’d love some input on solving this!

Do you mean the HTML tag? Surely you can just echo a title into it as you do with your H1 and other tags?

Yes, the html title tag. I haven’t had any luck so far getting the tag in there.

Can you post the source code to your page? NB: please use code or php tags as written in the IMPORTANT message shown when you reply to a post :slight_smile:

Here is a stripped down version without all the image code so it will read easier. As you can see I currently have a script that generates a page/bookmark title, but this does not replace the true html title that is SEO friendly. All my galleries end up with the same true title.

[php]

title tag here #content {width:620px; margin:0px auto;} #desc {margin:10px; float:left; font-family: Arial, sans-serif; font-size: 12px;} <?php if ($image == "001-") { print ('

h1 tag goes in this area

'); } elseif ($image == "002-") { print (' '); } else { print (' no image available '); } ?> [/php]

I think I understand your issue now. If you know the galleries will be one of a few names, you could use an array for set titles:

[php]$titles = array(
‘001-’ => ‘Some Title’,
‘002-’ => ‘Another Title’
);

if(isset($titles[$GALLERY_NAME])) {
echo ‘

’, $titles[$GALLERY_NAME], ‘

’;
} else {
echo ‘

Generic Title

’;
}[/php]

Each page will be a set name, so I could update the array as I add pages. Would this go outside of the gallery php section? With the sample code I posted, where would I insert this code? Before the title tag?

Made a mistake, I meant to put:

[php]$titles = array(
‘001-’ => ‘Some Title’,
‘002-’ => ‘Another Title’
);

if(isset($titles[$GALLERY_NAME])) {
echo ‘’, $titles[$GALLERY_NAME], ‘’;
} else {
echo ‘Generic Title’;
}[/php]

You would add more items to the array when you add pages and it would work on other pages as well. Place it inside of the HTML tags.

OK, I will play with that and get back to you. Thank you for your prompt responses!

Success! It took me a few tries to get all the variables right, I forgot to give the GALLERY_NAME variable the actual gallery name :-[ But I figured it out eventually :slight_smile:

Thanks again for your prompt help on this!

Sponsor our Newsletter | Privacy Policy | Terms of Service