26 Jul 2012

Changing the page title with AJAX Commands in Drupal

So you’ve loaded that new AJAX fragment using AJAX commands but you want to change the page title too?


The JavaScript

Create a new JavaScript plugin called jquery.changePageTitle.js and add it to the same pages your AJAX will be running in. Inside the JavaScript add…


The PHP

Alongside your other AJAX Commands in your Drupal module AJAX callback add the code below replacing ‘My great page title’ with any string or PHP string variable you want.


Bonus

A good suggestion to improve consistency is to format the title including the site name in the same way Drupal does it by default.