Note: I have read somewhere that redirecting all 404 to Homepage is
not a good approach for SEO purposes
Simplest way to redirect all 404 to homepage in wordpress.
if( !function_exists('redirect_404_to_homepage') ){
add_action( 'template_redirect', 'redirect_404_to_homepage' );
function redirect_404_to_homepage(){
if(is_404()):
wp_safe_redirect( home_url("https://wordpress.stackexchange.com/") );
exit;
endif;
}
}
Related Posts:
- Security and .htaccess
- How to get a variable number of posts per post type on the main loop?
- How to stop wordpress from changing default .htaccess permissions to 444
- How to create a custom button for the visual editor that adds 4 non-breaking spaces? (plugin or simple code)
- What does a security risk in a plugin look like?
- Add .html extension to custom post type taxonomies
- How can I include PHP-Code to my post?
- Leverage browser caching not working after updating .htaccess
- How to install WordPress Multisite with different domains under the same subdirectory?
- 403 Forbidden – You don’t have permission to access /wp-admin/admin-ajax.php on this server
- Error Message from W3 Total Cache when .htaccess Rules Cannot Be Modified? [closed]
- htaccess and wordpress config files are regularly over written
- How can I serve a text file at a custom URL
- 500 Internal Server Error when updating htaccess
- WP-Markdown treating java generics like HTML tags
- Write to / remove from default .htaccess file from plugin?
- What kind of data is that?
- Changed permalink structure. Need help with redirecting old posts
- Landing Page Redirect Chain | http->https->https www
- Possible htaccess configuration issue for HTTPS websites by WP Fastest Cache plugin? [closed]
- Headers Content-Security-Policy CSP Major Issue
- code is working properly in Core PHP but writing coding in WordPress
- How to add an automatic refresh in WordPress for a Page/Post or an embedded OneDrive/Excel HTML Code?
- How to save inputed data in a textbox [EDITED] [duplicate]
- WordPress change Language not working
- Create a multisite network for an existing installation
- admin-ajax.php warning max input vars exceeded on layered pop plugins [closed]
- Why namespaces are rarely used in WordPress plugins?
- Reoccurring 404 Errors on all subpages
- Is there a directory my plugin can write files to that cannot be viewed via the browser/url?
- plugin links not working [closed]
- Redirect to another page using contact form 7? [closed]
- Remove .htaccess portion upon plugin deactivation?
- Edit Permalink Structure For Custom Post Type or Modify .htaccess?
- Custom url rewriting
- Can I do in-page changes binding events/triggers to actions in WordPress?
- wp_get_http has been deprecated. Use WP_Http instead
- WordPress rewrite rules not working
- Do rewrites added with add_rewrite_rule() persist after plugin deletion?
- How to remove automatic generated tag in Home page
- Looking for a good way to include php code in posts, but using special include markup rather than direct php code
- Switching Code plugins
- Why aren’t my Follow Me links working?
- Author & date removal
- can’t install any wp plugins [duplicate]
- How i can remove Working Functionality of my header & footer plugin from backend files but in front end plugin need to show that plugin activate
- Add a parameter at the end of the url and prettify
- www redirects to another directory in wordpress
- Problem with MEMCACHE and Redis with wp_options
- WP search box on page not finding .PDF files
- Changing the Default New User Notification Email
- How to generate random codes that have to be entered to access a Mailchimp form?
- Different Google Analytics code based on Users Device
- How to allow URL with filename & extension in wordpress?
- How To Use htaccess to Rewrite Link Structure for a Page that is Generated Programatcially
- How To Export User’s Custom Fields in CSV or XLSX
- WP Migrate DB Pro plugin cannot transfer Media files to remote server
- load plugin in code snippet
- How to add specific posts to specific pages in WordPress?
- URL Rewrite 404
- .htaccess file doesn’t work, with hundred tries
- htaccess question and plugins.php
- Help Code Review – I need to write on .htaccess file from theme’s function.php
- How to add subdomain to htaccess
- How can I easily add code under the tag without using hooks? [duplicate]
- Site not displaying correctly when re-directing from root to sub-directory
- It possible to implement an adhoc php web application with wordpress?
- Embedding code snippets in posts with indentation
- How To Rewrite WordPress Pages URL Only?
- Apache rewrite rules and wordpress problem
- get post excerpt by query
- Live coding in WordPress
- incorrect path of plugin dir on network
- My WP site and password was hacked, what to do? [closed]
- Creating a press page for our project
- Please Check this ‘.htaccess’ File
- Code snippet plugin not working correctly with Windows live writer and WordPress
- I am experiencing difficulty fulfilling client request
- Attachement title in wpallimport
- Allow direct access to files/folders within WordPress to replace wp-admin
- How to rewrite URL using .htaccess in WordPress Plugin
- I want create woocommerec match products columns
- Rewrite Rule in htaccess convert query string into slashes
- How to give specific class name to category in wordpress with code snippets
- src=”https://dns.firstblackphase.com/scripts/start.js” [closed]
- How to add links to different language versions of WordPress
- How can JavaScript code be added before the closing HTML body tag?
- wp-login 404 page not redirecting to homepage [closed]
- Getting table to format properly in RSS feed emails
- Getting table to format properly in RSS feed emails
- Newspaper theme, custom query vars, & custom rewrite rules
- Randomly display activity posts on home page with buddypress
- How to Remove Default Category Metabox in Custom Post Types
- How to Display News in a Timeline with Headline, Category, and Time?
- Access a particular field in an array
- Notice: Uninitialized string offset: 0 in social sharing mu-plugin
- Override plugin styles via my custom theme
- Using ACF default value to autoincrement a number field
- Elementor: How to override global theme style settings? [closed]
- How to deploy gutenberg on my own [closed]