Reputation: 81
Is there a way to get the content of a H1 transferred to the TITLE tag and at the same time making it SEO-friendly?
I'm not going into detail why I want this, but I'd rather give you a clear example. I have this:
<h1>Site name / Category / Page title</h1>
And I want to copy that to the TITLE of that certain page:
<title>Site name / Category / Page title</title>
The easiest for me would be to do this with jQuery, but I guess that's not going to be safe for search engine robots?
Upvotes: 1
Views: 1015
Reputation: 1113
You could use directly as below
jQuery('html title').html(jQuery('h1').html());
OR
jQuery('html title').html(jQuery('#h1_id').html());
Consider h1_id as id of the tag
Upvotes: 0
Reputation: 228182
You have to use PHP. I think the "easiest" way is to use something like this:
<?php
$pageTitle = 'Site name / Category / Page title';
?>
...
<title><?php echo $pageTitle ?></title>
...
<h1><?php echo $pageTitle ?></h1>
...
You might want to look into a template system.
Upvotes: 2
Reputation: 3712
Why don't you generate the page on the server side with the title tag being the one you would like? If you set the title using jQuery, robots won't see it as they only look on the pure html.
Upvotes: 0
Reputation: 50832
Try (i assume you have only one h1-tag on that page)
$('title:first').html($('h1').html());
Upvotes: 0
Reputation: 8337
You're right: the robots won't notice, as they only look at the html in your server response. Use PHP instead.
Upvotes: 2