简体   繁体   中英

How can I include a code snippet in header of certain pages?

In OpenCart, the section is generated via header.tpl

How can I include a code snippet (such as Facebook conversion tracking code) only in the checkout/success page's header?

Replace common/home in the next example with the correct route:

if ((isset($this->request->get['route']) && $this->request->get['route'] == 'common/home')) { 
    $this->document->addScript('javascript/facebook_tracking_code.js');
}

Or do it inline (in a template):

<?php if ((isset($this->request->get['route']) && $this->request->get['route'] == 'common/home')) { ?>
<script src="javascript/facebook_tracking_code.js"></script>
<?php } ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM