{"id":6916,"date":"2022-12-22T10:21:17","date_gmt":"2022-12-22T15:21:17","guid":{"rendered":"https:\/\/themespress.ca\/?p=6916"},"modified":"2022-12-24T17:46:40","modified_gmt":"2022-12-24T22:46:40","slug":"redirecting-404-pages","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/redirecting-404-pages\/","title":{"rendered":"Redirecting 404 Pages"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><div class=\"vc_row wpb_row vc_row-fluid\"><div class=\"wpb_column vc_column_container vc_col-sm-12\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\n\t<div class=\"wpb_text_column wpb_content_element vc_custom_1671721681346\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p><strong>Redirecting 404 pages:<\/strong> There are many ways and reasons to redirect your 404 pages. With this tutorial, we will redirect 404 pages to the homepage with the <a href=\"https:\/\/developer.wordpress.org\/reference\/hooks\/template_redirect\/\" target=\"_blank\" rel=\"noopener\">template_redirect<\/strong><\/a> hook.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<\/div><\/div><\/div><\/div>\n<div class=\"vc_row wpb_row vc_row-fluid\"><div class=\"wpb_column vc_column_container vc_col-sm-12\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\"><h2 style=\"text-align: left\" class=\"vc_custom_heading vc_do_custom_heading vc_custom_1671721735184\" >Redirecting your 404 pages<\/h2><\/div><\/div><\/div><\/div><div class=\"vc_row wpb_row vc_row-fluid\"><div class=\"wpb_column vc_column_container vc_col-sm-12\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\"><div id=\"ts-enlighterjs-container-4514696\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-4514696\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"php\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">add_action(&#039;template_redirect&#039;, &#039;themespress_redirect_404_to_homepage&#039;, 999);\nfunction themespress_redirect_404_to_homepage(){\n    if(!is_404())\n    return;\n    wp_redirect(home_url());\n    exit;\n}<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element vc_custom_1671722090656\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>This function will ensure that all 404 oages will be redirected and in this case a 404.php template is not necessary in your theme.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"Redirecting 404 pages: There are many ways and reasons to redirect your 404 pages. With this tutorial, we will redirect 404 pages to the homepage with the template_redirect hook. Redirecting<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/redirecting-404-pages\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":6915,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[],"class_list":["post-6916","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6916","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/users\/81"}],"replies":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/comments?post=6916"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6916\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/6915"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=6916"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=6916"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=6916"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}