0

Do I want to add bing script code for adding bing search engine to my magento2 website then where to add that script code in Magento2?. I don't know how to implement this task. Can you please help me?

5
  • did you get script by bing to add in your site ? Commented Aug 17, 2018 at 5:01
  • Hi @ Ansar Husain, yes I have Commented Aug 17, 2018 at 5:03
  • admin->content->design->configration->themes(click edit which one current theme) -> HTML head (click) -> Scripts and Style Sheets (paste js code here) Commented Aug 17, 2018 at 5:07
  • Hi @Ansar Husain, I want to add bing search only in the checkout page Commented Aug 17, 2018 at 5:15
  • I have added answer please check it Commented Aug 17, 2018 at 5:25

1 Answer 1

0

Use below code for add script only for checkout page.

1. create registration.php in app/code/Checkout/BingScript

<?php
    \Magento\Framework\Component\ComponentRegistrar::register(
        \Magento\Framework\Component\ComponentRegistrar::MODULE,
        'Checkout_BingScript',
        __DIR__
    );

2. create module.xml in app/code/Checkout/BingScript/etc

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
    <module name="Checkout_BingScript" setup_version="0.0.1" />
</config>

3.Create a checkout_index_index.xml in app/code/Checkout/BingScript/view/frontend/layout

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <script src="Checkout_BingScript::js/bing.js"/>
    </head>
</page>

4. put your js code in app/code/Checkout/BingScript/view/frontend/web/js/bing.js

5. run commands

php bin/magento setup:upgrade

php bin/magento setup:static-content:deploy -f

php bin/magento cache:flush

5
  • Hi@Ansar Husain, I am trying to in my localhost magento2 I could not find this file path app\design\frontend\Vendor\Themename\Magento_Checkout\layout. This is the my file path C:\xampp7.0\htdocs\magento2test\app\design\frontend\Magento Commented Aug 17, 2018 at 5:34
  • That means you did not use any theme yet in your setup Commented Aug 17, 2018 at 5:35
  • Hi@Ansar Husain, I am using default theme Commented Aug 17, 2018 at 5:36
  • I have created module for you check it Commented Aug 17, 2018 at 5:47
  • Hi@Ansar Husain, I will try and I have created a custom module in my localhost Commented Aug 17, 2018 at 6:14

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.