handling attachments redirections

This commit is contained in:
Antoine M 2024-05-21 11:55:47 +02:00
parent 66b1a36a1d
commit 71a2d6118a
2 changed files with 18 additions and 1 deletions

View File

@ -1 +0,0 @@
<h1>salut</h1>

18
attachment.php Normal file
View File

@ -0,0 +1,18 @@
<?php
$attachment_id = get_the_ID();
$title = get_the_title();
$document_permalink = get_the_permalink(get_the_ID());
$pdf_url = wp_get_attachment_url(get_the_ID());
if ($pdf_url) {
wp_redirect($pdf_url);
exit();
} else {
// Si l'URL du document est vide, redirige vers la page 404
global $wp_query;
$wp_query->set_404();
status_header(404);
get_template_part(404);
exit();
}