0

I'm using the CiviCRM plugin for WordPress, and in the plugin's main file, civicrm.php, it calls add_action() to add a function to wp_head() in order to merge CiviCRM's header with my theme's header:

add_action( 'wp_head', array( $this, 'wp_head' ) ); 

The actual function within civicrm.php is found below:

public function wp_head() { echo "calling wp_head"; //added by me to test if the code gets called // CRM-11823 - If Civi bootstrapped, then merge its HTML header with the CMS's header global $civicrm_root; if ( empty( $civicrm_root ) ) { return; } $region = CRM_Core_Region::instance('html-header', FALSE); if ( $region ) { echo '<!-- CiviCRM html header -->'; echo $region->render( '' ); } } 

I have confirmed that the code gets called when I switch to the twentyfifteen theme, but on my custom theme (which is based on an old version of Roots), this code does not get called. I have also confirmed that my custom theme is actually calling the main WordPress wp_head() function.

Any ideas on what could be going wrong in my custom theme that would cause this custom wp_head hook to not get called or otherwise error out in some way?

3
  • 1
    Can you verify that wp_head() is being called in your theme's header? Commented Sep 12, 2015 at 18:27
  • 1
    Have you tried adding your own hook to wp_head to see if that works? Commented Sep 12, 2015 at 19:34
  • Yes - I made sure that the main wp_head() function is actually being called in my theme's header. I put an echo in another function and it's being printed. The CiviCRM function, however, is not. Commented Sep 12, 2015 at 20:34

2 Answers 2

1

Can we think litter bit different way:

add_action('wp_head','new_wp_head'); function new_wp_head() { echo "calling wp_head"; global $civicrm_root; if ( empty( $civicrm_root ) ) { return; } $region = CRM_Core_Region::instance('html-header', FALSE); if ( $region ) { echo '<!-- CiviCRM html header -->'; echo $region->render( '' ); } } 

Make sure in which file you put this and it's hook with your theme or plugins.

0

I figured out the issue:

When CiviCRM was applying the template in civicrm.basepage.php, $page_template was coming back as page.php, but my base template was actually named base.php.

I added the following code in my theme's initialization and it resolved the issue:

add_filter( 'civicrm_basepage_template', 'psca_civicrm_basepage_template' ); function psca_civicrm_basepage_template( $template ) { return 'base.php'; } 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.