0

Google Webmaster Tools and marketing suppliers, pricecomparision suppliers, Google Analytics, Facebook Ads etc. etc.... all wants their individual codes inplemented on convertion pages. Not on all pages, but on surtain pages, typically the order succes page.

And they all want their code in the HEAD tag of individual pages... and THIS is the challenge...

Also surtain pages in magento do not have title tags, example /rss/ and /sales/guest/form/‎ so google webmaster tools are complaining about it... It´s the same issue... = code in the individual head of the individual page...

How is that possible, to implement individual code to head (not header) -content, on individual pages in magento ?

Thanks in advance...

  • what you want to remove header from those page – Amit Bera Nov 10 '14 at 14:17
  • from where you have seen this code please attach a screen shot – Amit Bera Nov 10 '14 at 14:20
2

Each page has it's own layout handle usually built this way: [module]_[controller]_[action].
For example, for the order success page you have the layout handle <checkout_onepage_success> You can in one of your layout pages to inject blocks or texts to the head section.
If you don't have dynamic values you can use the text approach.

<checkout_onepage_success>
    <reference name="head">
        <block type="core/text" name="tracker_code" as="tracker_code">
            <action method="setText">
                 <text><![CDATA[your script goes here. Add the <script type="text/javascript"></script> if needed.]]></text>
            </action>
        </block>
    </reference>
</checkout_onepage_success>

If you have dynamic values, use the template approach and add your code in a template where you can use PHP functions.

<checkout_onepage_success>
    <reference name="head">
        <block type="core/template" name="tracker_code" as="tracker_code" template="tracker/code.phtml" />
    </reference>
</checkout_onepage_success>

Then create the file app/design/frotnend/{package}/{theme}/template/tracked/code.phtml with what you need added to the head. Example:

<script type="text/javascript">
    alert('D'oh!');
</script>

If you need to add multiple scripts to the same page make sure the name and as attributes for your block are different.

  • What about inserting a block there - within reference name="head"... would that be possible, to support multiple stores and to avoid future file editing - then just handle the content and scripts directly in blocks in the backend ? Would that be possible ? – Supertankeren Nov 10 '14 at 14:30
  • I just gave you the main idea. The way you use it depends totally on you. What you mentioned should work. In fact here is how I would do it. I would create a backend CRUD section for managing the tracking codes where I would select or fill in a layout handle. Then have only one block with one template that retrieves all the tracking codes for the current page's handle. To add one block for all pages just replace in the checkout_onepage_success in the example above with default. – Marius Nov 10 '14 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.