Reputation: 35
i have used RSSEO plugin for optimizing my joomla site, however i want my h1 tag in custom components and pages to be similar to page title. Tried below
<h1>
<script type="text/javascript">
<!--
document.write(document.title);
//-->
</script></h1>
The above script is able to display h1 tag, but when checks source code its not seo friendly as display script
I think i need server side php code, have tried using
<h1><?php echo $PageTitle ?></h1>
But above is not displaying any value. only leading to blank h1 tags
Can anyone suggest and advise pls to do it effectively
thanks
Upvotes: 1
Views: 4168
Reputation: 13
This works in Joomla! 2.5.x:
<?php
$document = JFactory::getDocument();
?>
<h1><?php echo $document->getTitle(); ?></h1>
Upvotes: 0
Reputation: 3124
Try this :
<?php
$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$page = fread(fopen($url, "r"), 2048); // first 2KB
if(preg_match("/<title>(.+)<\/title>/i",$page,$result))
{
echo "The title of $url is $result[1]</b>";
}
else
{
echo "The page doesn't have a title tag";
}
?>
This will load faster as you want :
Upvotes: 0
Reputation: 5615
Joomla $document will contain the title, so simply inject it in your component / template:
<?php
$document = JFactory::getDocument();
echo "<h1>".$document->getMetaData('title')."</h1>";
?>
this should do the trick.
Upvotes: 0
Reputation: 10388
Try this:
HTML:
<h1 id="pagetitle"></h1>
JavaScript:
document.getElementById('pagetitle').innerHTML = document.title;
If you want the script inline:
<h1 id="pagetitle"></h1>
<script>
document.getElementById('pagetitle').innerHTML = document.title;
</script>
Upvotes: 2