Created
February 5, 2025 16:29
-
-
Save emulsion-io/c09d157f6c10e9b0320cefbea857e205 to your computer and use it in GitHub Desktop.
Add shortcut for edit content with Wordpress in front
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
function ajouter_raccourci_js() { | |
if (is_user_logged_in() && current_user_can('edit_posts')) { // Vérifie que l’utilisateur est connecté et a les droits d’édition | |
?> | |
<script> | |
document.addEventListener("keydown", function(event) { | |
if (event.ctrlKey && event.key === "e") { | |
event.preventDefault(); // Empêche toute action par défaut | |
let editLink = document.querySelector("a[href*='action=edit']"); | |
if (editLink) { | |
window.location.href = editLink.href; // Redirige vers l'éditeur | |
} | |
} | |
}); | |
</script> | |
<?php | |
} | |
} | |
add_action('wp_footer', 'ajouter_raccourci_js'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment