Search code examples
htmlcssdrupaldrupal-7

Page title not updating? Drupal/PHP hook title


I'm trying to change my page title. To visit the page - click here.

This is written as a custom module within Drupal 7. The file is called wb_spc.module for this module code in JSFiddle, please click here.

I've tried changing lines 51 and 59 but this won't change the h1 page title?

Please see a code snippet below:

/**
 * Implements hook_menu().
 */
function wb_spc_menu() {
  $items = array();

  // Admin configuration group.
  $items['admin/config/wb_spc'] = array(
    'title' => 'Workbooks Self-Assessment CRM ROI Calculator',
    'description' => 'Administer WB CRM Requirements',
    'access arguments' => array('administer wb crm requirements'),
  );

  // Admin configuration - Settings.
  $items['admin/config/wb_spc/manage'] = array(
    'title' => 'Workbooks Self-Assessment CRM ROI Calculator Settings',
    'description' => 'Manage WB CRM Requirements settings and configurations.',
    'access arguments' => array('administer wb spc requirements'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('wb_spc_admin_settings_form'),
  );

  $items[variable_get('wb_spc_path')] = array(
    'title' => 'Workbooks Self-Assessment CRM ROI Calculator', 
    'page callback' => 'drupal_get_form', 
    'page arguments' => array('wb_spc_form'),
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );

  $items['wb_spc/test'] = array(
    'title' => 'TESTING - Workbooks Self-Assessment CRM ROI Calculator', 
    'page callback' => 'wb_spc_test', 
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );

  $items['wb_spc/results/%'] = array(
    'title' => 'WB Show PDF', 
    'page callback' => 'wb_spc_show_pdf', 
    'page arguments' => array(2),
    'access arguments' => array('access content'),
  );
  return $items;
}

Solution

  • In the page (the one you see as a user), add this:

    drupal_set_title('Page title goes here');
    

    Change the <h1>, i believe the page title will be changed also if you do. If you want page title to be other than <h1> use the method drupal_set_title('Page title goes here');

    To change it from only a certain page use:

    if($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] == 'www.yourdomain.com/rest/of/url'){
        drupal_set_title('Page title goes here');
    }