Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #885510
    xtjoeywx
    Participant

    What’s the best way to add a Trust Pilot script to the head of my site? I would like to add it to my child theme. Also, I would like to add a certain Trust Pilot widget div code to all pages through my child theme. Also, is there a way to turn it off on certain pages easily if I want to?

    <script type="text/javascript" src="//widget.trustpilot.com/bootstrap/v5/tp.widget.sync.bootstrap.min.js"></script>

    <div class="trustpilot-widget" data-locale="en-US" data-template-id="MY-ID" data-businessunit-id="MY-OTHER-ID" data-style-height="130px" data-style-width="100%" data-theme="light" data-stars="4,5">
        <a href="https://www.trustpilot.com/review/mysite.com" target="_blank">Trustpilot</a>
    </div>
    #886402
    Christian
    Moderator

    Hey there,

    Please see the articles below to learn how to add scripts to WordPress.

    http://www.wpbeginner.com/wp-tutorials/how-to-properly-add-javascripts-and-styles-in-wordpress/

    Add Javascript and CSS files to the Head and Footer in WordPress

    To add a widget, please see https://community.theme.co/kb/unlimited-sidebars/. To turn off a widget or a sidebar for a page, you would need to choose a page template with no sidebar. Please see https://community.theme.co/kb/page-templates/ for more details about page templates.

    Thanks.

    #898297
    xtjoeywx
    Participant

    I don’t want to add the trust pilot widget to a sidebar or a widget because it spans all the way across a page. It usually right above the footer (see attached image). I would like to add the div code (above) to all of the page templates so that the widget just shows up on the bottom of the page above the footer. Same with the woocommerce product pages. How do I do that using the child theme?

    #898718
    Thai
    Moderator

    Hi There,

    Please add the following code under functions.php file locates in child theme:

    add_action( 'wp_head', 'x_print_custom_scripts' );
    function x_print_custom_scripts(){
      ?>
      <script type="text/javascript" src="//widget.trustpilot.com/bootstrap/v5/tp.widget.sync.bootstrap.min.js"></script>
      <?php
    }
    
    add_action( 'x_after_view_global__footer-widget-areas', 'x_print_custom_HTML' );
    function x_print_custom_HTML(){
      ?>
      <div class="trustpilot-widget" data-locale="en-US" data-template-id="MY-ID" data-businessunit-id="MY-OTHER-ID" data-style-height="130px" data-style-width="100%" data-theme="light" data-stars="4,5">
          <a href="https://www.trustpilot.com/review/mysite.com" target="_blank">Trustpilot</a>
      </div>
      <?php
    }

    Hope it helps 🙂

    #899288
    xtjoeywx
    Participant

    That works but I would like to have it above the widgeted footer area, not inside of it. Above the entire black footer in the white area (between the body and the widgeted footer). Also, I would like to put a different Trust Pilot div code in the same location on the page but on all of the woocommerce product pages.

    In other words, there will be one trust pilot widget on all of the posts and pages. Then there will be one on all of the woocommerce product pages.

    Code for posts and pages:

      <div class="trustpilot-widget" data-locale="en-US" data-template-id="My-ID" data-businessunit-id="My-ID" data-style-height="180px" data-style-width="100%" data-theme="light" data-stars="4,5">
        <a href="https://www.trustpilot.com/review/intellibed.com" target="_blank">Trustpilot</a>
    </div>

    Code for products:

      <div class="trustpilot-widget" data-locale="en-US" data-template-id="My-ID" data-businessunit-id="My-ID" data-style-height="220px" data-style-width="100%" data-theme="light" data-stars="4,5">
        <a href="https://www.trustpilot.com/review/intellibed.com" target="_blank">Trustpilot</a>
    </div>
    #900194
    Zeshan
    Member

    Hi there @xtjoeywx,

    Thanks for writing back!

    In this case, please use this code instead:

    add_action( 'wp_head', 'x_print_custom_scripts' );
    function x_print_custom_scripts(){
      ?>
      <script type="text/javascript" src="//widget.trustpilot.com/bootstrap/v5/tp.widget.sync.bootstrap.min.js"></script>
      <?php
    }
    
    add_action( 'x_before_view_global__footer-widget-areas', 'x_print_custom_HTML' );
    function x_print_custom_HTML(){
    
      // Code for products
      if ( x_is_product() ): ?>
        <div class="trustpilot-widget" data-locale="en-US" data-template-id="My-ID" data-businessunit-id="My-ID" data-style-height="220px" data-style-width="100%" data-theme="light" data-stars="4,5">
            <a href="https://www.trustpilot.com/review/intellibed.com" target="_blank">Trustpilot</a>
        </div>
      <?php 
      // Code for posts & pages
      else: 
      ?>
        <div class="trustpilot-widget" data-locale="en-US" data-template-id="My-ID" data-businessunit-id="My-ID" data-style-height="180px" data-style-width="100%" data-theme="light" data-stars="4,5">
            <a href="https://www.trustpilot.com/review/intellibed.com" target="_blank">Trustpilot</a>
        </div>
      <?php
    }
    

    Hope this helps. 🙂

    Thank you!

    #900536
    xtjoeywx
    Participant
    This reply has been marked as private.
    #900540
    xtjoeywx
    Participant
    This reply has been marked as private.
    #901722
    Thai
    Moderator

    Hi There,

    Please update the previous code a bit:

    add_action( 'wp_head', 'x_print_custom_scripts' );
    function x_print_custom_scripts(){
      ?>
      <script type="text/javascript" src="//widget.trustpilot.com/bootstrap/v5/tp.widget.sync.bootstrap.min.js"></script>
      <?php
    }
    
    add_action( 'x_before_view_global__footer-widget-areas', 'x_print_custom_HTML' );
    function x_print_custom_HTML(){
    
      // Code for products
      if ( x_is_product() ){ ?>
        <div class="trustpilot-widget" data-locale="en-US" data-template-id="My-ID" data-businessunit-id="My-ID" data-style-height="220px" data-style-width="100%" data-theme="light" data-stars="4,5">
            <a href="https://www.trustpilot.com/review/intellibed.com" target="_blank">Trustpilot</a>
        </div>
      <?php 
      // Code for posts & pages
      } else { 
      ?>
        <div class="trustpilot-widget" data-locale="en-US" data-template-id="My-ID" data-businessunit-id="My-ID" data-style-height="180px" data-style-width="100%" data-theme="light" data-stars="4,5">
            <a href="https://www.trustpilot.com/review/intellibed.com" target="_blank">Trustpilot</a>
        </div>
      <?php
      } 
    }

    Hope it helps 🙂

    #902286
    xtjoeywx
    Participant

    Perfect! Thank you.

    #903149
    Friech
    Moderator

    We’re delighted to assist you with this.

    Cheers!

  • <script> jQuery(function($){ $("#no-reply-885510 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>