• Resolved Ekapon

    (@ekapon)


    I’m totally a newbie. The code is from Booking.com Affiliate. It is to display Booking.com banner on our site. I would like to have it displayed at the main content area, not widget on sidebar. I tried copy/paste to the text editor but it doesn’t show when preview. I also tried using the plugin “Code Embed” but it doesn’t work neither.

    I can only add it to widget and see it’s running here… https://www.kohtaocompleteguide.com/test-booking-affiliate/

    The code is below.

    Many thanks.

    <ins class="bookingaff" data-aid="1160320" data-target_aid="1159340" data-prod="banner" data-width="200" data-height="200" data-banner_id="31403">
        <!-- Anything inside will go away once widget is loaded. -->
        <a href="//www.booking.com?aid=1159340">Booking.com</a>
    </ins>
    <script type="text/javascript">
        (function(d, sc, u) {
          var s = d.createElement(sc), p = d.getElementsByTagName(sc)[0];
          s.type = 'text/javascript';
          s.async = true;
          s.src = u + '?v=' + (+new Date());
          p.parentNode.insertBefore(s,p);
          })(document, 'script', '//aff.bstatic.com/static/affiliate_base/js/flexiproduct.js');
    </script>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi,
    If you would like to add the script to the content (in posts/pages) then you can do it by creating a new shortcode. Add the following code in a new .php file in the wp-content/plugins directory and activate it on the Plugins screen in wp-admin:

    <?php
    /*
    Plugin Name: Booking Affiliate Shortcode
    Description: Use [booking-aff] to insert the affiliate shortcode
    Author: MyThemeShop
    Version: 0.1
    */
    
    add_shortcode( 'booking-aff', 'mts_booking_aff_script' );
    function mts_booking_aff_script( $atts ) {
    	$script = '<ins class="bookingaff" data-aid="1160320" data-target_aid="1159340" data-prod="banner" data-width="200" data-height="200" data-banner_id="31403">
        <!-- Anything inside will go away once widget is loaded. -->
        <a href="//www.booking.com?aid=1159340">Booking.com</a>
    </ins>
    <script type="text/javascript">
        (function(d, sc, u) {
          var s = d.createElement(sc), p = d.getElementsByTagName(sc)[0];
          s.type = \'text/javascript\';
          s.async = true;
          s.src = u + \'?v=\' + (+new Date());
          p.parentNode.insertBefore(s,p);
          })(document, \'script\', \'//aff.bstatic.com/static/affiliate_base/js/flexiproduct.js\');
    </script>';
    	return $script;
    }

    Then you can just add [booking-aff] wherever you want the banner to appear.
    Hope that helps.

    Thread Starter Ekapon

    (@ekapon)

    Thank you MyThemeShop!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How do we add Booking.com code to page?’ is closed to new replies.