Theming image buttons in Drupal

October 4th, 2010

Here is a simple code snippet for those who want to make some of the submit buttons on their Drupal website image buttons:

[code lang="php"]
function MYTHEME_button($element) {
   if ($element['#value'] == t('Search')) {
    $element['#src'] = drupal_get_path('theme', 'MYTHEME') . '/images/search_button.png';
    $element['#button_type'] = 'image_button';
  if ($element['#button_type'] == 'image_button') {
     return theme_image_button($element);
  else {
    return theme_button($element);

The above code goes into your template.php file in your theme folder. Make sure to rename MYTHEME with your theme name. You can look up $element['#value'] from the page code, it is the ‘value’ of the button element. The code snippet is for Drupal 6.

Max Rakhimov

Max is a Web Developer with over 12 years experience in information systems and software development. He holds Bachelor of Science Degree in Computer Science from Drexel University and is a Subject Matter Expert in Drupal framework.

Leave a Reply