שלבים להטמעת הפתרון:
functions.php של תבנית הבת באתר שלכם, או השתמשו בתוסף כמו Code Snippets להוספת הקוד:function enforce_google_drive_direct_download_links() {
?>
<script>
function convertGoogleDriveLinks() {
// סריקה של כל הקישורים בדף
const allLinks = document.querySelectorAll('a[href*="drive.google.com/file/d/"]');
allLinks.forEach(link => {
const href = link.getAttribute('href');
// זיהוי ה-ID של הקובץ מתוך הקישור
const fileIdMatch = href.match(/\/file\/d\/(.*?)\//);
if (fileIdMatch && fileIdMatch[1]) {
const fileId = fileIdMatch[1];
// יצירת קישור להורדה ישירה
const downloadLink = `https://drive.google.com/uc?export=download&id=${fileId}`;
link.setAttribute('href', downloadLink);
link.setAttribute('download', "); // מוסיף תמיכה בדפדפנים מסוימים
}
});
}
// הפעלת הפונקציה בעת טעינת הדף
document.addEventListener('DOMContentLoaded', convertGoogleDriveLinks);
// מעקב אחר שינויים בדף עבור אלמנטים דינמיים
const observer = new MutationObserver(convertGoogleDriveLinks);
observer.observe(document.body, { childList: true, subtree: true });
</script>
<?php
}
add_action('wp_footer', 'enforce_google_drive_direct_download_links');