Answers.Body: <p>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:</p>
  
  <pre><code>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 );
    }
  }
  </code></pre>
  
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-29T18:07:58.297Z
Answers.Text: Christian, This worked perfectly for me thanks!
Answers.UserDisplayName: matthew
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-17T17:31:32.423Z
Answers.LastActivityDate: 2017-01-17T17:37:14.330Z
Answers.LastEditDate: 2017-01-17T17:37:14.330Z
Answers.UserDisplayName: Christian Wach
Body: <p>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.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>The php function that handles all of this, is the 'prerender' function in the CiviCRM_For_WordPress_Shortcodes class of civicrm.shortcodes.php.</p>
  
  <p>The shortcode I'm trying to add is as follows...</p>
  
  <pre>
  
  do_shortcode('[civicrm component="profile" gid="14" mode="create" hijack="0"]')
  
  </pre>
  
  <p>Does anyone know if this behaviour can be modified, so that the files are enqueued on all WP pages?</p>
  
  <p>Thanks for any help!</p>
  
  <p>Matt</p>
  
Tags: <wordpress><profile>
Title: Enable use of do_shortcode when using CiviCRM and WordPress templates
ThreadText: # Enable use of do_shortcode when using CiviCRM and WordPress templates
  
  (Asked by: username_0 on 2017-01-17)
  
  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!
  
  Matt
  
  **Tags:** wordpress, profile
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-01-17. Score: 3 | Accepted answer
  
  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.
  
  > **Comments:**
  > **username_0**: username_1, This worked perfectly for me thanks!  
  
  ---
  
  