How to create a sub theme in drupal 7

By

November 19, 2012DrupalNo comments

Drupal provides a simple way to inherit the base themes through the concept called subtheme.

Advantages of Creating Sub theme:

  1. No need of hacking the core themes
  2. All the styles of base theme will be inherited to sub theme, less coding

Lets see how to create a sub theme in drupal. For this example i have used bartik theme as base theme.

Step 1: Create a new folder in sites/all/themes/ path as shown below
eg: sites/all/themes/mydons/

Step 2: To create a new theme we need to write the .info file. Our sub theme is named as mydons so we need to create mydons.info file. Since we are creating a sub theme we need to specify the directive as base theme = bartik
Except the name,description and base theme directive other directives looks same as base theme.

The final version of mydons.info looks as shown below

Step 3: For this subtheme i created a single css file called mystyle.css under css directory in our subtheme. You can have any name for your stylesheet and it must be specified in your theme .info file as stylesheets[all][] = css/mystyle.css

I have just included a single line in mystyle.css as shown below

Step 4: Now go to drupal admin and check whether the new theme is listed. if it is listed click the Enable and set default link as shown below

Step 5: Finally the Performance cache needs to be cleared to view the change.

The final output of our theme looks as shown below

Tags:

Leave a Reply