Created
August 20, 2025 18:05
-
-
Save loorlab/a9832178904d4cca0d7fcb1c0be9fe5e to your computer and use it in GitHub Desktop.
Simple Modal WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// functions.php | |
add_action('wp_footer', function() { ?> | |
<div id="simple-modal" style="display:none; position:fixed; top:0; left:0; width:100%; height:100%; background:rgba(0,0,0,0.5); z-index:9999; justify-content:center; align-items:center;"> | |
<div style="background:#fff; padding:20px; border-radius:10px; max-width:400px; text-align:center; position:relative;"> | |
<span id="close-modal" style="position:absolute; top:10px; right:15px; cursor:pointer; font-size:20px;">×</span> | |
<h2>Hola đź‘‹</h2> | |
<p>Este es un modal simple en WordPress.</p> | |
</div> | |
</div> | |
<script> | |
document.addEventListener("DOMContentLoaded", function() { | |
const modal = document.getElementById("simple-modal"); | |
const close = document.getElementById("close-modal"); | |
// Mostrar el modal automáticamente después de 1s | |
setTimeout(() => { modal.style.display = "flex"; }, 1000); | |
// Cerrar al hacer click en la X | |
close.onclick = () => modal.style.display = "none"; | |
// Cerrar si se hace click fuera del contenido | |
window.onclick = (e) => { if (e.target === modal) modal.style.display = "none"; }; | |
}); | |
</script> | |
<?php }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment