Quote:
Originally Posted by farout
So I have my main php-page (ajax #!) that loads all other html-pages as dynamic content.
When a dynamic page is loaded the title and description of my main page stays the same.
How can I display a unique title tag and description for each dynamic page and will that show up in search results as well?
|
The general consensus is that search engines don't read or run javascript when indexing a web page. This means that any dynamic page titles would not be captured. In fact, nor would your AJAX-loaded pages themselves, unless you have a non-javascript fallback - which you should do anyway. Search google for the phrase "progressive enhancement" and give a few sites a read on that topic to understand both why it is important, and why it will benefit you.
Generally speaking for what you are describing, you would have your main landing page with actual proper links to other pages (not something like href="javascript
:..." or href="#" or the like, you would actually want to link to your content like href="/someotherpage.php") so that 1) any actual user who does not have javascript available or enabled can still access your site's content, and 2) search engines can still find and index your content. Your PHP page should provide code for an ENTIRE proper page by default (including the html tags, head, and full body - absolutely everything needed to match your main page's style and serve as a completely independent web page). Then, with proper href attribtes in place on your menu anchor tags you can still use AJAX to call in the content without a page load for those users whose settings support it.
For one example, on window load you can loop through the menu container and set onclick event handlers on all of the anchor tags present in that menu. The onclick event handler in those cases can trigger an AJAX request function that will check the href of the link that was clicked, append a $_GET variable to the URL to mark it as an AJAX request (e.g. "?ajax=1"), and then query the very same PHP file as before with that slightly modified URL. Now, when the AJAX request marker is present in the URL requested your PHP page can be set up to SKIP outputting everything (html, head, body tags, etc.) EXCEPT the page contents that you want to deliver.
This way you still get the exact same AJAX functionality in your "best case scenario" while maintaining SEO relevance and basic functionality for the blind, for people without a mouse input device, and for people with javascript either disabled or not available. It's the best of both worlds and only requires a few minor changes on your part to implement it.