Answers.Body: <p>Well silly me never even thought to check if it would work as-is from my WordPress plugin, and I assumed (never assume) that it would need some special wrapper/call to make it happen.</p>
  <p>The answer (as pointed out by Demerit) is that there is no equivalent... the code is identical... it will just work as it is.</p>
  <pre><code>require_once(ABSPATH . 'wp-includes/pluggable.php');
  add_filter( 'civicrm_buildForm', 'my_customhook_civicrm_buildForm', 10, 4  );
  function my_customhook_civicrm_buildForm($formName, &amp;$form){
    if ($formName == &quot;CRM_Activity_Form_ActivityLinks&quot;) {
      //if (check_some_other_stuff_to_see_if_its_the_page_i_want) {
  
        // HOW DO YOU MAKE IT WORK? You just stick the exact same code here that was in the CiviCRM plugin:
        CRM_Core_Region::instance('page-body')-&gt;add( ['script' =&gt; &quot;cj('#my-customfield-id').css('font-size', '75%');&quot;] );
  
      //}
    }
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-08-07T15:43:50.670Z
Answers.LastActivityDate: 2024-08-07T15:43:50.670Z
Answers.UserDisplayName: jsherk
Body: <p>I have a custom civicrm plugin, and I am using the buildForm function to modify some css on a page. Here is simple example from my civicrm plugin, where I modify some CSS on a specific page for a specific id:</p>
  <pre><code>function my_customfunctions_civicrm_buildForm($formName, &amp;$form) {
    if ($formName == &quot;CRM_Activity_Form_ActivityLinks&quot;) {
      //if (check_some_other_stuff_to_see_if_its_the_page_i_want) {
        CRM_Core_Region::instance('page-body')-&gt;add( ['script' =&gt; &quot;cj('#my-customfield-id').css('font-size', '75%');&quot;] );
      //}
    }
  }
  </code></pre>
  <p>So now I am working on doing the same thing from WordPress plugin, but I am not sure how to do the <code>CRM_Core_Region::instance('page-body')-&gt;add</code>. This is what I have so far in my wordpress plugin:</p>
  <pre><code>require_once(ABSPATH . 'wp-includes/pluggable.php');
  add_filter( 'civicrm_buildForm', 'my_customhook_civicrm_buildForm', 10, 4  );
  function my_customhook_civicrm_buildForm($formName, &amp;$form){
    if ($formName == &quot;CRM_Activity_Form_ActivityLinks&quot;) {
      //if (check_some_other_stuff_to_see_if_its_the_page_i_want) {
  
        // HOW DO I DO THE EQUIVALENT OF: CRM_Core_Region::instance('page-body')-&gt;add here in my plugin?
  
      //}
    }
  }
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-08-07T14:17:32.290Z
Comments.Text: What happens when you call CRM_Core_Region::instance() from your wordpress plugin?
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-08-07T15:40:07.530Z
Comments.Text: oh my... well I honestly thought there would be some sort of wrapper/call that I would have to put it in, to make it work, and never directly tried to call it that way... but yes it just works as is! There is nothing special to do at all.
Comments.UserDisplayName: jsherk
Tags: <wordpress><hooks>
Title: How to do equivalent of CRM_Core_Region::instance('page-body')->add from WordPress plugin?
ThreadText: # How to do equivalent of CRM_Core_Region::instance('page-body')->add from WordPress plugin?
  
  (Asked by: username_0 on 2024-08-06)
  
  I have a custom civicrm plugin, and I am using the buildForm function to modify some css on a page. Here is simple example from my civicrm plugin, where I modify some CSS on a specific page for a specific id:
  
  ```
  function my_customfunctions_civicrm_buildForm($formName, &$form) {
    if ($formName == "CRM_Activity_Form_ActivityLinks") {
      //if (check_some_other_stuff_to_see_if_its_the_page_i_want) {
        CRM_Core_Region::instance('page-body')->add( ['script' => "cj('#my-customfield-id').css('font-size', '75%');"] );
      //}
    }
  }
  
  ```
  
  So now I am working on doing the same thing from WordPress plugin, but I am not sure how to do the `CRM_Core_Region::instance('page-body')->add`. This is what I have so far in my wordpress plugin:
  
  ```
  require_once(ABSPATH . 'wp-includes/pluggable.php');
  add_filter( 'civicrm_buildForm', 'my_customhook_civicrm_buildForm', 10, 4  );
  function my_customhook_civicrm_buildForm($formName, &$form){
    if ($formName == "CRM_Activity_Form_ActivityLinks") {
      //if (check_some_other_stuff_to_see_if_its_the_page_i_want) {
  
        // HOW DO I DO THE EQUIVALENT OF: CRM_Core_Region::instance('page-body')->add here in my plugin?
  
      //}
    }
  }
  
  ```
  
  **Tags:** wordpress, hooks
  
  > **Comments:**
  > **username_1**: What happens when you call CRM_Core_Region::instance() from your wordpress plugin?  
  > **username_0**: oh my... well I honestly thought there would be some sort of wrapper/call that I would have to put it in, to make it work, and never directly tried to call it that way... but yes it just works as is! There is nothing special to do at all.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2024-08-07. Score: 0 | Accepted answer
  
  Well silly me never even thought to check if it would work as-is from my WordPress plugin, and I assumed (never assume) that it would need some special wrapper/call to make it happen.
  
  The answer (as pointed out by username_1) is that there is no equivalent... the code is identical... it will just work as it is.
  
  ```
  require_once(ABSPATH . 'wp-includes/pluggable.php');
  add_filter( 'civicrm_buildForm', 'my_customhook_civicrm_buildForm', 10, 4  );
  function my_customhook_civicrm_buildForm($formName, &$form){
    if ($formName == "CRM_Activity_Form_ActivityLinks") {
      //if (check_some_other_stuff_to_see_if_its_the_page_i_want) {
  
        // HOW DO YOU MAKE IT WORK? You just stick the exact same code here that was in the CiviCRM plugin:
        CRM_Core_Region::instance('page-body')->add( ['script' => "cj('#my-customfield-id').css('font-size', '75%');"] );
  
      //}
    }
  }
  
  ```
  
  
  ---
  
  