Redirect wp-sitemap.xml not working
Redirect wp-sitemap.xml not working
Redirect wp-sitemap.xml not working
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);
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
You’ll have to exit afterwards. add_filter( ‘template_redirect’, ‘wpse85164_query_var_template’ ); function wpse85164_query_var_template( $template ) { if ( ‘basic’ === get_query_var( ‘template’ ) ) exit( dirname( __FILE__ ).’/basic.php’ ); return $template; }
template_redirect called twice
How to add a switch to admin area which enables/disables crisis-mode: Redirect all traffic to certain page if switch is enabled
I want to replace after WordPress is completely loaded
This can be achieved using a Virtual Post. See this link on how to do it. https://ashiqur.com/how-to-add-a-virtual-page-in-wordpress/
In you actual code you can see this: if ( is_user_logged_in() || ! is_page() ) return; This code does this: if user is logged in or is not in a page, then return/do nothing. You need to remove ! is_page(): add_action( ‘template_redirect’, function() { if ( is_user_logged_in() ) return; $restricted = array( 250, 253 ); … Read more
Nope. Use the wp_enqueue_scripts hook directly for enqueing all styles and scripts. There’s no need to hook into template_include for that. template_include is specifically for modifying templates. //Adding and Encuing styles for Front Page add_action( ‘wp_enqueue_scripts’, ‘front_page_design’ ); function front_page_design(){ if ( is_front_page() || is_home()) { wp_enqueue_style( ‘home_page_style’, get_stylesheet_directory_uri() . ‘/index-style.css’, array(‘handle_of_main_style’) ); } } … Read more