I am trying to add a simple CiviCRM profile shortcode to a template of my theme, but the required CiviCRM files are not being loaded in the wp_head and therefore the shortcode does not render the profile form.

I have traced the issue to CiviCRM only loading these files if the shortcodes are being added to the content of the page or post.

This means that not only does the do_shortcode function not render CiviCRM shortcodes, but also any ACF (Advanced Custom Fields) fields created cannot render the shortcode either.

The php function that handles all of this, is the 'prerender' function in the CiviCRM_For_WordPress_Shortcodes class of civicrm.shortcodes.php.

The shortcode I'm trying to add is as follows...

do_shortcode('[civicrm component="profile" gid="14" mode="create" hijack="0"]')

Does anyone know if this behaviour can be modified, so that the files are enqueued on all WP pages?

Thanks for any help!


1 Answer 1


Personally, I don't think loading CiviCRM on all pages regardless of whether there's a shortcode present is a good idea. What you should be able do, however, is something along the lines of:

add_action( 'get_header', 'force_civi_scripts_to_load' );
function force_civi_scripts_to_load() {
  if ( is_page_template( 'your-template.php' ) ) {
    add_action( 'wp_enqueue_scripts', array( civi_wp(), 'front_end_page_load' ), 100 );

This should force CiviCRM to load the appropriate scripts when (and only when) the template that your shortcode is located in is loaded. If, however, your shortcode sits in a template part, then you may have to be less specific about when you force CiviCRM's scripts to load.

  • Christian, This worked perfectly for me thanks!
    – matthew
    Jan 29, 2017 at 18:07

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.