WordPress Plugin PopUp Maker – Chiudere automaticamente un PopUp dopo un certo numero di Secondi – Guida

WordPress Plugin PopUp Maker – Chiudere automaticamente un PopUp dopo un certo numero di Secondi – Guida

Se utilizzate il plugin di WordPress Popup Maker quasi certamente vi sarete imbattuti nella necessità di far chiudere il popup che state utilizzando automaticamente dopo un determinato tempo.

Purtroppo si tratta di una funzione non disponibile direttamente nel plugin che fortunatamente è facilmente generabile con un piccolo ritocco al file functions.php

Chiudere il Popup automaticamente dopo 10 Secondi

Testato fino alla versione 1.16.7 di Popup Maker

Il seguente esempio di codice è stato progettato per chiudere un popup (ID: #pum-123 ) dopo 10 secondi.

Copiare, incollare e modificare il codice seguente nel file functions.php del tema figlio, oppure utilizzare il plugin My Custom Functions per installare il codice.

Sostituire il numero ID del popup in questo esempio di codice con il valore assegnato al popup. È possibile trovare l’ID andando in Popup Maker > Tutti i popup > Classi CSS. Il valore intero è aggiunto al nome della classe ‘popmake-‘.

<?php
/**
 *  Note 1: Replace the placeholder popup ID used below ('#pum-123') with
 *  the value '#pum-{integer}'.  From the WP Admin, refer to 'Popup Maker'
 *  -> 'All Popups' -> 'CSS Classes (column)' -> to find the integer value
 *  assigned to the popup targeted to close with this code snippet.
 *
 *  Note 2: In the code example below, the units of time are milliseconds (ms).
 *  1 second = 1000 ms; 10 seconds = 10000 ms.
 *
 *  Add the following code to your theme (or child-theme)
 *  'functions.php' file starting with 'add_action()'.
 * -------------------------------------------------------------------------- */
add_action( 'wp_footer', 'my_custom_popup_scripts', 500 );
/**
 * Add a script to automatically close a popup after X seconds.
 *
 * @since 1.0.0
 *
 * @return void
 */
function my_custom_popup_scripts() { ?>
    <script type="text/javascript">
        (function ($, document, undefined) {

            $('#pum-123') // Change 123 to your popup ID number.
                .on('pumAfterOpen', function () {
                    var $popup = $(this);
                    setTimeout(function () {
                        $popup.popmake('close');
                    }, 10000); // 10 Seconds
                });

        }(jQuery, document))
    </script><?php
}

Il valore pum-123 dovrete sotituirlo con quello assegnato al vostro PopUp come già detto. Inoltre potrete inserire più di un valore contemporaneamente ( se avete più Popup Attivi ) utilizzando questa sintassi :

$('#pum-123,#pum-456,#pum-789')

per dubbi o suggerimenti...ci scriviamo nei commenti!!!

WordPress Plugin PopUp Maker – Chiudere automaticamente un PopUp dopo un certo numero di Secondi – Guida

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

Rispondiamo a tuttilascia un commento per ricevere dettagli o inviaci una email per proporre la stesura di nuove guide.
Available for Amazon Prime