Adding the Lightbox Cart.js to your Wordpress Theme Header

We often get asked how to add the cart.js script tag (that generates the lightbox cart on your website) to Wordpress.

Most Wordpress fields strip <script> tags, so the best way to add the cart.js line is to add it to your theme header so it will be available on every page and post.

 

The Script Tag:

<script type="text/javascript" src="https://getdpd.com/js/cart.js"></script>

 

Adding it to your Theme Header:

1.  Log in to your wordpress admin

2.  Go to the Appearance menu in the left column and select "editor":

 

3.  Find the Header.php file and insert the complete script tag above right before your closing HEAD tag:

 

4.  Save header.php and check your site.  The script tag for cart.js should appear right before your closing head tag on every page.

Note:  Some themes have multiple headers like "header-post, header-fullwidth, etc."   Generally, you can ignore these and put the script tag in ONLY the header.php file, which is the standard wordpress header that is loaded on every page.

 

Have more questions? Submit a request

Comments

  • Avatar
    Maria Mar

    Sorry, Jason, I thinks I'm not explaining myself properly. I'm not placing the code in the header as such. I'm placing it in the menu using a widget that my theme (suffusion) provides. My theme has many areas to put widgets, and one of them is in the top right bar. That's what I did. If WP is stripping it, I imagine?? tha I have to get into the theme's code for that widget or the WP for the menu. I'm not sure. But I can't find anything that says "theme-header" so it's beside the point. There are several "sidebar" php areas, so I'm thinking one of them should be. I hope this is more clear. Thanks

  • Avatar
    Jason Chance

    Maria,

    There is a very good chance that wordpress will strip the javascript tag from widgets in the sidebar. The safest way is to add it to your theme header. You can add the view cart/checkout button to a widget if you like.

  • Avatar
    Maria Mar

    Oops, Jason, did it again. I did not specify that I'm talking about the navigation menu at the top, not the sidebar. My theme allows for widgets that can be placed in the appearance/menu page as mega-menus. So I have the checkout in the top bar menu, above the header, to the right and I love it. You can see it here: http://dreamalchemist.com. I can't see where to fix it in the editor, though. Do you know? Thanks!

Powered by Zendesk