10 min read

(For more resources related to this topic, see here.)

Setting up a CiviCRM theme in Drupal

CiviCRM administration screens take up a lot of browser real estate. How CiviCRM looks is determined by what themes you are using in your CMS. Problems arise when you use your main website theme to display CiviCRM pages. All the customizations, blocks of information, and layouts suddenly get in the way when you want to administer CiviCRM. The trick is to use a different theme for CiviCRM.

How to do it…

This is very easy to accomplish, and just uses a configuration screen in Drupal.

  1. Make sure you have the CiviCRM theme module enabled.
  2. Navigate to admin/appearance in Drupal by clicking on the Appearance button. This page shows the themes that are currently installed within our CMS—in this case, Drupal.
  3. Make sure that any themes you wish to use are enabled.
  4. At the foot of the screen, configure CiviCRM Administration theme.

How it works…

Drupal uses the page URL to check if you are administering CiviCRM. If you are, the pages are displayed using the CiviCRM administration theme.

It’s a good idea to select a flexible-width theme with sidebars. Garland is a good example. The flexible width accommodates CiviCRM displays nicely.

Once the administration theme is selected, navigate to admin/structure/blocks. Here you will see various blocks provided by the CiviCRM module. You can now place these blocks within your administrative theme.

Pay special attention to the visibility settings for these blocks, so that they only appear when using CiviCRM.

There’s more…

In Drupal, there is an additional setting that controls which theme is used to display public CiviCRM pages, for example, event sign-up pages.

See also

Setting up cron using cPanel

Cron is a time-based scheduler that is used extensively throughout CiviCRM. For example, you might want to use CiviCRM to send out an e-mail newsletter at a particular time, or you might want to send out a reminder to participants to attend an event. CiviCRM has settings to accomplish all these tasks, but these, in turn, rely on having “master” cron set up. Cron is set up on your web server, not within CiviCRM.

How to do it…

There are many different ways of setting up cron, depending on your site-hosting setup. In this example, we are using cPanel, a popular control panel that simplifies website administration.

  1. Make a note of your CMS site administrator username and password.
  2. Make a note of your CiviCRM site key, which is a long string of characters used to uniquely identify your CiviCRM installation. It is automatically generated when CiviCRM is installed, and is stored in the civicrm_settings. php file. Using a text editor, open up the CiviCRM settings file located at /sites/default/civicrm_settings. php. Around line 170, you will see the following entry:

    define( 'CIVICRM_SITE_KEY',
    '7409e83819379dc5646783f34f9753d9' );

    Make a note of this key.

  3. Log in to cPanel and use the cPanel File Manager to explore the folders and files that are stored there. You are going to create a file that contains all the necessary information for cron to work. You can choose to create the cron file anywhere you like. It makes sense to keep it in the home directory of your webserver—that is, the first directory you get to once you start exploring.
  4. Create a file called CiviCron.php. The naming does not particularly matter, but it must be a PHP file.
  5. Insert the following code:

    // create a new cURL resource
    $ch = curl_init();
    // set URL and other appropriate options
    curl_setopt($ch, CURLOPT_URL,
    curl_setopt($ch, CURLOPT_HEADER, 0);
    // grab URL and pass it to the browser

    • Substitute http://myDrupalsite.com with your own domain
    • Substitute admin with your own CMS admin username
    • Substitute adminpassword with your own CMS admin password
    • Substitute the key value with the site key from civicrm_settings.php
  6. Save this file and then navigate to cron in cPanel.

  7. Select an appropriate cron interval from the Common Settings list. Choosing an appropriate cron interval may take some experimentation, depending on how your site is set up. In the Command field, enter the following address:

    php /home/site_account_name/public_html/CiviCron.php

    The portion after php is the absolute path to the CiviCron.php file you created in step 4.

  8. Click on Add New Cron Job.

How it works…

All cron does is execute the URL that is constructed in the cron file.

The following piece of code does the work:

curl_setopt($ch, CURLOPT_URL,

The URL contains the information on permissions (the username, the password, and the site key) to execute the cron.php file provided by the CiviCRM module.

Getting cron to work is critical to getting CiviCRM working properly. If you get into difficulties with it, the best solution is to contact your hosting company and seek guidance.

To test that your cron job is actually working, carry out the following instructions. In the cPanel cron screen, set it to send you an e-mail each time the cron command is run. The e-mail will contain an error message if the cron fails. Failures are generally due to an incorrect setting of the path, or a permissions problem with the username, password, or site key.

Adding items to the CiviCRM navigation menu

As you begin to use CiviCRM, you will want to provide administrative shortcuts. You can do this by adding custom menu blocks within your CMS or editing the navigation menu in CiviCRM.

How to do it…

CiviCRM has a fully customizable navigation menu. You can edit this menu to get one-click access to the features you use most.

  1. Navigate to a page that you want to use as the link destination for a menu item. For example, you could navigate to Contacts | Manage Groups , and then select a suitable group.
  2. Copy the page URL in the browser location. In this example, it would be as follows:


  3. Navigate to Administer | Customize Data and Screens | Navigation Menu. This displays the CiviCRM navigation menu in tree form.
  4. Click on the left arrow on each Parent menu item to expand it. You can now explore all the child menu items.
  5. Click on the Add Menu item button at the top of this screen. This brings up the Add Menu Item edit screen.

  6. Enter the name of the menu item in the Title field
  7. Enter the URL (that you copied) into the URL field.
  8. Select a parent to make the menu item appear as the child of another menu item. If you don’t select a parent, the item will appear on the main CiviCRM menu bar.
  9. Select one or more permissions in the Permission field to control who can use the menu item. These are CMS permissions, so we must ensure that these are set correctly in our CMS for the menu item to behave properly.

How it works…

CiviCRM stores new menu items, and displays them according to where they are placed in the menu tree and what permissions a user may have to use them.

See also

Refreshing the dashboard

By default, CiviCRM sets the auto-refresh period for the home page dashboard to 1 hour. In a busy setting, this is too long, and you constantly have to click on the Refresh Dashboard data button to get the information on the dashboard up to date.

How to do it…

Changing the setting is simply a matter of visiting the CiviCRM administration pages:

  1. Navigate to Administer | System Settings | Undelete, Logging and ReCAPTCHA.
  2. Change the Dashboard cache timeout value from 1440 (that’s 1 hour in seconds) to a smaller figure.

Changing display preferences

By default, CiviCRM displays a lot of data on the contact summary screen. Sometimes, this can lead to a cluttered display that is hard to use and slow to load.

How to do it…

CiviCRM components can add to the clutter on the screen. Here we can disable unwanted components and then fine-tune the display of other elements in the contact summary screen.

  1. Navigate to Administer | System Settings | Enable CiviCRM Components, and disable any unused CiviCRM components.
  2. Navigate to Administer | Customize data and screens | Display preferences.
  3. Control which tabs are displayed in the detail screen (for each contact), using the checkboxes.

  4. Control which sections you want to see when editing an individual contact, by checking the checkboxes in the Editing Contacts section.

  5. Drag the double-arrow icon to move the sections up and down the contact editing screen.

See also

Replacing words

This is useful for fine-tuning your website. For example, you could replace US spelling with UK spelling (thus avoiding installing the UK language translation). Or you might want to change the wording on parts of a standard form without having to make a custom template.

How to do it…

The words—or sentences—that we want to replace are called strings. In CiviCRM, we can enter the strings we don’t want, and replace them with strings we do want.

  1. Navigate to Administer | System Settings | Customize Data and Screens | Word Replacement.

    In this example, I am replacing the US spelling of “Organization” with the UK version, “Organisation”.

  2. Use the Exact Match checkbox to match words precisely. This would then exclude plurals of the word from being matched. All word replacements are case sensitive.

Setting up geocoding

Geocoding allows you to do location-based searching and to display the maps of contacts.

How to do it…

You need to set a mapping provider—that is a service that will provide you with the visual maps—and a geocoding provider, which will translate your contact addresses into latitude and longitude coordinates.

  1. Navigate to Administer | Localization | Address settings. In Address Display, make sure that the Street Address Parsing checkbox is ticked.
  2. Navigate to Administer | System Settings | Mapping and Geocoding. Set Mapping Provider to Google or Openstreetmap. Set Geocoding Provider to Google.
  3. Navigate to Administer | System Settings | Scheduled Jobs. The Geocode and Parse Addresses scheduled job should now be enabled. You can set how regularly you want CiviCRM to geocode your address data.

How it works…

Geocoding Provider finds latitude and longitude coordinates for each contact address. Mapping Provider uses this information to draw a local map, with a pointer for the contact. Geocode and Parse Addresses do the geocoding work each day, though you can change this in the settings.

There’s more…

Google currently limits geocoding requests to 2,500 per 24 hours. So, if you exceed this limit, Google may not process requests; it may even restrict access to their geocoding service should you continue to break this limit. This is a problem when you have thousands of addresses to process—for example, after a big import of address data.

CiviCRM does not have a tool to place a daily limit on the number of contacts that are processed each day. But you can put parameters into the Geocode and Parse Addresses scheduled job that provide a range of contact IDs to process. You would have to change this each day to work your way though all your contacts.

  1. Navigate to Administer | System Settings | Scheduled Jobs, and edit the Geocode and Parse Addresses scheduled job.
  2. In the Command Parameters box, enter:

    start= 1

    1 would be the ID of your first contact. If you have access to your database tables, check the database table civicrm_contact to know what the first value for your contacts is.

See also

Subscribe to the weekly Packt Hub newsletter

* indicates required


Please enter your comment!
Please enter your name here