For some reason my theme function is not being found by Drupal. I swear I have followed everything and spent hours of time trying to make this work to no avail. Plus with not a single answer in the past 48 hours, Drupal's online support forum is about as much help as a bike with no wheels. Maybe some of you can figure out what is going wrong with this code.

    function opti_format_results($response) {

    $results = array(

    '#theme' => 'opti_design'


    if ($response) {

    foreach ($response as $key => $value) {

    $results['result '.$key] = array(

    '#markup' => $response[$key]['title'],

    // '#link' => $response[$key]['link'],



    } else {

    $results[] = opti_nothing_found();


    return $results;


    function Opti_Search_theme() {

      return array(

    'opti_design' => array(

    'render element' => 'optisearch'




    function theme_opti_design($variables) {

    $content = $variables['optisearch'];


    $content = "What is going on??";

    echo "IT HAS THEMED! :D";

    return $content;


The error is quite simple. "Theme hook opti_design not found." Can someone please tell me what is wrong. Everything looks fine. The hook_theme() function was set properly, and worked in an entirely other module just fine but for whatever reason will not do it's job here. I feel like it is something simple but I am not seeing it. Thanks for any and all help.

1 Answer 1


Your logic is fine, so check these:

  1. Your module is named 'Opti_Search". If not, Opti_Search_theme() needs to be changed to MODULENAME_theme(), and the caches cleared. This one seems most likely given the error message you received.
  2. You've cleared the caches since implementing hook_theme().
  3. The module is installed and enabled.
  • Thank you very much! Drupal does not seem to like capital letters in hook names. It must be all lower case otherwise it won't work. I changed Opti_Search to opti_search and it works fine now. It is strange, because the files are all Opti_Search, so is the info file but the actual script just doesn't like those capitals. Thanks again! :D
    – Eulerfan
    Commented Jul 13, 2014 at 22:03
  • @Eulerfan Yes, please review the Drupal coding standards for recommended best practice. Your coding style needs work. Also, if the answer works, you should mark it as "accepted" Commented Jul 13, 2014 at 23:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.