Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use a DIV's Contents as an HTML Page's Title?

I'm building a social media based news site, and for the sharing element to work (Twitter, Facebook etc.), the page's value must reflect it's "headline" (e.g. when the page is shared online, the title should be "Man Bites Dog", not "My News Site").

I've tried multiple PHP and jQuery solutions, but nothing seems to work. There is a complication, though. The site's content is delivered via RSS feed from Blogger, and I'm using jQuery to parse the "headline" RSS and display it on the page. Since the "headline" content is dynamically generated when the page loads, could this cause the problem?

If so, is there a way to use the same RSS-based method to change the value?

Here's the code I'm using to aggregate and display the RSS "headline" feed...

<script type="text/javascript">

        jQuery(function($) {
    $('#headline').rssfeed('http://cjfoote.blogspot.com/feeds/posts/default?alt=rss', {
        limit: 1
    });
});

</script>
like image 571
Chris Foote Avatar asked Dec 06 '25 12:12

Chris Foote


1 Answers

Remember:

If you use JS to change the title a searchrobot cannot read the new title. So it don't effect your SEO.

If you use PHP to change the title it has a positive influence on your SEO.


If you want to use PHP, look for simpleXML to read the RSS file and then simply echo the correct headline.

like image 176
Wouter J Avatar answered Dec 09 '25 00:12

Wouter J



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!