Snippet per aggiungere un bottone "Torna Su":
<?php
// Aggiungi il pulsante Torna Su
add_action('wp_footer', 'add_back_to_top_button');
function add_back_to_top_button() {
?>
<!-- Pulsante Torna Su -->
<div id="back-to-top" style="display: none;">
<button onclick="scrollToTop()">Torna Su</button>
</div>
<style>
#back-to-top {
position: fixed;
bottom: 20px;
right: 20px;
z-index: 1000;
}
#back-to-top button {
padding: 10px 15px;
background-color: #0073aa;
color: #ffffff;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
#back-to-top button:hover {
background-color: #005177;
}
</style>
<script>
document.addEventListener("DOMContentLoaded", function() {
var backToTopButton = document.getElementById("back-to-top");
window.onscroll = function() {
if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) {
backToTopButton.style.display = "block";
} else {
backToTopButton.style.display = "none";
}
};
window.scrollToTop = function() {
window.scrollTo({ top: 0, behavior: 'smooth' });
};
});
</script>
<?php
}
?>
