skip to Main Content

So I’m trying to use a Bootstrap Modal, and I want it to appear after a click (onclick method).

Right now I have this

       $("#cancelPObtn").on("click", function(){ $("#error-dialog").modal();});
<script src=""></script>
<link rel="stylesheet" type="text/css" href="">
<script src=""></script>

<a href="#" class="btn btn-danger" id="cancelPObtn" data-toggle="modal" href="#error-dialog">Yes, cancel it</a>
 <div class="modal hide fade" id="error-dialog">
   <div class="modal-header">
        <a class="close" data-dismiss="modal">x</a>
        <h3>Cancel Purchase Order?</h3>
   <div class="modal-body">
   <div class="modal-footer">
       <a href="#" class="btn btn-danger btn-modal btn-cancel"  data-dismiss="modal">Yes, cancel it</a>
       <a href="#" class="btn" data-dismiss="modal">Nevermind</a>
<!-- I HAVE THE JAVASCRIPT ON MY POST TOO, USING <script type="text/javascript"> -->

So, it appears to be working, everywhere, but on my WordPress post I can’t make it work! I’ve added the JS + CSS Files from Bootstrap on my header.php

What could be the issue here?

Thank you!



  1. You should read up on enqueuing scripts and styles in WordPress. WordPress has it’s own way of including the script files and the stylesheets that you should familiarize yourself with. A lot of times, what ends up happening is either the files aren’t included correctly, or in the wrong order, or without the dependencies they might need. Adding the links directly to header.php is strongly discouraged.

    Login or Signup to reply.
  2. In addition to using wp_enqueue_script as recommended above, I would ensure you’re writing non-conflicting jQuery, as WordPress plugins sometimes come bundled with their own JavaScript libraries, which can cause issues.

    See below:

    <script type="text/javascript">
      jQuery(function($) {
        $('#cancelPObtn').click(function() {

    Also, WordPress is probably calling its own instance of jQuery, so you can use window.jQuery to test before including your own, like this:

    <script type="text/javascript">
      window.jQuery || document.write('<script src=""></script>');


    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top