WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How would I put the following code, for a certain shopping cart, just before the closing body tag in my WordPress site? In the footer? It seems to me that I would only want to call startcart() for product pages. Thanks very much.

<script language="javascript" type="text/javascript">
share|improve this question
up vote 3 down vote accepted

If you're just using a small script or other markup, you can hook a function to the wp_footer filter, which is included in all modern themes:

function wpse_77196_script_in_footer() {
    <script language="javascript" type="text/javascript">
add_filter( 'wp_footer', 'wpse_77196_script_in_footer' );

However, if your JavaScript code is more substantial, or you wish to use built-in libraries such as jQuery, you should put the code in an external file, enqueue it properly using the wp_enqueue_script() function:

    'myscript', // lowercase name of script
    get_template_directory_uri() . '/js/script.js', // url to script
    array( 'jquery' ), // libraries to use
    false, // version of script (false is WP version)
    true // load in footer (true) or head (false)? 

You can read more about how to use the wp_enqueue_script() functon at the Codex

If you need more help, please post a comment below.

share|improve this answer
Thank you very much! I think I'm good now. – SteveR Dec 26 '12 at 1:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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