Custom WordPress Popups

I have implemented a custom popup on my WordPress website and it works fine when tested on a simple `index.html` file on the local server. However, when I embed the code in the `header.php` and `style.css` files of WordPress on the local server, the popup does not work as expected. Below is the code snippet along with the placement within the files:

In `/wordpress/wp-content/themes/parasponsive/header.php`, I have placed the following jQuery code in the head section:

<script>
$(document).ready(function(){

    $(function(){
        $('span.clickMe').click(function(e){
            var hiddenSection = $('section.hidden');
            hiddenSection.fadeIn()
                .css({ 'display':'block' })
                .css({ width: $(window).width() + 'px', height: $(window).height() + 'px' })
                .css({ top:($(window).height() - hiddenSection.height())/2 + 'px',
                    left:($(window).width() - hiddenSection.width())/2 + 'px' })
                .css({ 'background-color': 'rgba(0,0,0,0.5)' })
                .appendTo('body');
     
                $('span.close').click(function(){ $(hiddenSection).fadeOut(); });
        });
    });

});

Next, just above the closing header tag in the same `header.php` file, I added the HTML code:

    </section>

<section class="hidden">
    <article class="popup">
        <span class="close">Close Me</span>
        <p>
            This is a test.
        </p>
    </article>
</section>

Finally, in the `/wordpress/wp-content/themes/parasponsive/style.css` file, I included the styles for the elements:

 section.center {
    max-width: 150px;
    margin: 100px auto;
}
span.clickMe {
    font-size: 30px;
}
span.clickMe:hover {
    cursor: pointer;
    color: green;
}
section.hidden {
    display: none;
    position: fixed;
}
section article.popup {
    position: relative;
    width: 400px;
    height: 300px;
    background: #e3e3e3;
    color: #222;
    border: 1px solid #333;
    border-radius: 3px;
    padding: 5px 7px;
    margin: 10% auto;
}
span.close {
    text-transform: uppercase;
    color: #222;
}
span.close:hover{
    color: red;
    cursor: pointer;
}

However, despite implementing all these changes, the popup is still not clickable. What could be causing this issue?

Answer №1

Here's a suggestion:

    ( function( $ ) {
            $('span.clickMe').click(function(e){
                var hiddenSection = $('section.hidden');
                hiddenSection.fadeIn()
                    // reveal section.hidden
                    .css({ 'display':'block' })
                    // expand to full screen
                    .css({ width: $(window).width() + 'px', height: $(window).height() + 'px' })
                    .css({ top:($(window).height() - hiddenSection.height())/2 + 'px',
                        left:($(window).width() - hiddenSection.width())/2 + 'px' })
                    // dimmed background
                    .css({ 'background-color': 'rgba(0,0,0,0.5)' })
                    .appendTo('body');
                    // console.log($(window).width() + ' - ' + $(window).height());
                    $('span.close').click(function(){ $(hiddenSection).fadeOut(); });
            });
        } ) (jQuery);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A technique to trigger the display of a detailed grid by clicking in the master section

Currently, I am in the process of creating a reusable master-detail grid component using Backbone. My goal is to incorporate an event that triggers the loading of the detail grid whenever a user clicks on a row within the master grid. However, I am facin ...

The colorbox popup is experiencing difficulty loading the Google Map from an inline div specifically in IE7

Using the following code, you can load a Google map from an inline div to a Colorbox popup window in all modern browsers. However, it may not work with outdated browsers like IE7. <head> <script src="http://maps.googleapis.com/maps/api/js?key=/// ...

Maintaining content after page refresh with jQuery Ajax

Utilizing jquery and ajax in my project. Here's a snippet of the code I plan to implement. If I refresh the page after receiving a response (in this case, a form), I lose all the content. Is there a way to store/cache the response data in a variable s ...

CSS alert problem encountered

I have an HTML and CSS notification template that I would like to incorporate into my PHP code. You can view the template here. HTML <div class="alert-box error"><span>error: </span>Write your error message here.</div> &l ...

Remove the right margin on the bootstrap container

I am currently working on creating dashboards using the Python library called Dash, and I have encountered an issue with Bootstrap components. Specifically, I am unable to remove the right margin from the container. I have tried using class_name='m-0& ...

Ensure that the child element maintains equal height and width measurements within a row that is distinct

Is there a way to arrange 4 items inside a flex container in a 2 X 2 grid layout while ensuring that they all have the same width and height? I've tried using flex-grow: 1;, but since the children are in different flex containers, they do not obey th ...

How can I use CSS to clip the United States, specifically Tennessee and Nashville, from the left side?

For my ASP.NET generated hyperlink that says "select location", when the user clicks on it, they are redirected to a new page where they can choose a different location at /change-location/default.aspx. This could be any country, state, or city in the worl ...

"What is the best way to retrieve the value of a div element with jquery

Attempting to retrieve the value of a div using jQuery in Chrome console from this HTML: <div class="col-md-3"> <div class="vou-col" style="cursor: pointer"> <h4>Free Large Bucket</h4> <span class="sku-info">Voucher ...

Wordpress causing Jquery to malfunction; PHP function not executing

Looking to incorporate a script into my WordPress function.php file. Here's what I have so far: <?php function add_google_jquery() { if ( !is_admin() ) { wp_deregister_script('jquery'); wp_register_script('jquery', ...

The modal box should adjust its height to perfectly accommodate the content within

I'm in the process of developing a straightforward modal (popup) window, using as few lines of code as possible... just the basics. The modal has a maximum width of 650px and its height adjusts to fit the content. In case the content exceeds the avai ...

What could be the reason for Angular Router to receive query parameters twice?

I have an application that consists of two pages with lists. On Page A, clicking on an item will display the corresponding detail page. The detail page contains a list of sub-items, and clicking on any sub-item navigates to Page B with the sub-item's ...

Pictures in Windows 7 have shifted to the left

After a recent migration to the Windows 7 operating system at my company, I encountered an issue. While using the same Visual Studio 2010 master file that was working fine on my Windows XP machine, I noticed that all the images below were now shifted to t ...

Leverage Html5 to open and retrieve data from an Excel document

Is there a method to access excel file data using HTML5 while uploading the file on the client side? I have come across the use of reader in JavaScript, but unsure how it can be helpful in this scenario. Is there a way to read excel file data seamlessly ...

Creating a Popup with a Hazy Background: A Step-by-Step Guide

I've been working on implementing a popup on my existing page that opens 4.5 seconds after the page loads. I want to add a blur effect to the background when the popup appears. I've tried various methods to add the blur effect to the main div, bu ...

The information is being transmitted via an Ajax request, however, the PHP script is not able to

I am facing an issue with sending form data to a php script. Despite having what seems like correct Javascript and PHP code, the script is not receiving the data as expected. Before making the ajax request, the data appears to be in order. However, upon ...

Jquery vertical menu with a dynamic sliding animation from the right side to the left side

Hello everyone, I am looking to have my vertical menu slide from right to left instead of the typical top to bottom sliding that comes with using .toggle() in jQuery. Specifically, when the hamburger menu is clicked, I want the menu to slide out from right ...

Discover the secrets to replicating the mesmerizing horizontal scrolling menu akin to the

What is the most effective way to create a horizontal menu similar to the innovative Google picture menu? Could someone kindly share their knowledge and provide the code for achieving the same outcome? ...

Transforming Codeigniter Forms into Custom HTML

I need help converting the following CodeIgniter code into HTML. Can someone assist me with this? <?php echo form_open('contact/create_member'); echo form_input('name', set_value('name', ' Name')); echo form_in ...

AJAX request triggers only on the initial occasion

I am currently facing an issue with my AJAX call that is set to delete a record from a table generated by django-tables2. Each row in the table has a delete button marked with a class of delete_relationship_button and an id representing the primary key of ...