Grap Html title and turn it into Meta title

Hi, is this possible? I want to grab the product title on my product pages and then turn it into a meta title. For example this page http://shockingtshirts.com/?i=3583109393 has the title “Does Not Compute”, could I some how get that and then turn it into the meta title before the page is output to html?

This is quite a tricky and complex CGi backend which is why I can’t get the meta title.

How would you like to use it? You’re going to have to provide more information than what you have already. :slight_smile:

Looking at the html output, it appears you’re using WordPress, does it support the dynamic naming of the page title via its API?

You say “it doesn’t work”, yet haven’t explained how you would like it to work.

The above code doesn’t work, not sure how it would anyway, can you explain please how I would use it? The relax t-shirt has this ID 2244574196 and that ID is for another tshirt, the one I posted first.

that’s not how it is, wish it was that easy

Well, http://shockingtshirts.com/?i=2244574196 doesn’t even list the ‘Relax’ title…

Hmm…


<?php

function get_product_name($id){
  preg_match(
    '~(?<=<!--\\s)(.+)(?=\\s-->)~',
    (string)file_get_contents(
      'http://shockingtshirts.com/?i=' . $id
    ),
    $match
  );
  return isset($match[0]) ? $match[0] : '' ;
}

$product_name = get_product_name('3583109393');

?>

Edit: Oh, actually it does. This would be a much better match that the HTML comment I found in your source.

<span class="cpshopbreadcrumbtext">Relax</span>

uhhhh the code is already there for you to grab the name

<title><?= $product_name; ?></title>

Sorry for not explaing more. It really is quite complicated. It is wordpress but I have implemented a shopping cart for Cafepress called CPshop into wordpress. But I hit a brick wall so I thought maybe there is an easy way to grab the product name with php and output as the meta title.

This thread here has all the details: http://www.marty.net/cgi/marty/board/messageboard?board=cpperl&action=display&num=1281538796

I don’t think it is. :confused:


<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>	Buy crazy t-shirts online</title>
<meta name="author" content="Shocking T-Shirts" />