How to redirect my homepage

Two options that I’ve used to solve this issue: Homepage template file Create a front-page.php file, which is the template file used by WordPress for your homepage, it takes priority over page.php, see this for more reading on page template priority. In your front-page.php file, add the following code: <?php header(‘Location: https://yoursite.com/subpage’); die(); 301 Redirect … Read more

Where does the redirect from shortlink to permalink happen?

That’s handled by the redirect_canonical function, set up as a default template_redirect filter. So it can be customized either by : a template_redirect filter, with a priority value lower than 10, so it runs before the redirect_canonical function (which will eventually skip the next filters by making a redirect). a redirect_canonical filter called by the … Read more

Load a specific post if user tries to access 404 page

This is the final code that works. I had to set $wp_query->is_single = true; manually: add_action( ‘template_redirect’, function(){ global $wp_query; if ( is_404() ){ $id = 1; // the post corresponding to hello-world if ( $id ) { $wp_query->is_404 = false; status_header(200); header(“HTTP/1.1 200 OK”); $wp_query->query(“page_id=$id&post_type=post”); $wp_query->the_post(); $wp_query->is_single = true; } } }, 999);

Creating FPDF directly in the browser using template_rediect

Use ob_start();, ob_clean(); before outputting the PDF to make any uwanted content is not written while cretaing PDF. add_action(“template_redirect”, “checkRedirect”); function checkRedirect() { $url = (isset($_SERVER[‘HTTPS’]) && $_SERVER[‘HTTPS’] === ‘on’ ? “https” : “http”) . “://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]”; $slug = strtolower(basename($url)); if ($slug == “pdf”) { ob_start(); require_once(getPath() . “fpdf.php”); $pdf = new \FPDF; $pdf->AddPage(); $pdf->SetFont(‘Arial’,’B’,16); $pdf->Cell(40,10,’Hello … Read more