You’re looking to remove a post-type slug completely from the url. This is documented in this answer. Remember that after making any changes to post urls, you should resave your permalink structure for the changes to fully take effect.
Edit:
You can additionally redirect from the old location (with the slug), this way:
function na_redirect_slug_requests() {
$post = get_queried_object();
// If our custom-post-type
if ( ! empty( $post->post_type ) && 'events' === $post->post_type ) {
$url = get_permalink( $post );
// And the custom-post's url doesn't match the one we're looking at...
if ( false === strpos( $url, $_SERVER['REQUEST_URI'] ) ) {
// Then let's redirect.
wp_safe_redirect( $url, 301 );
exit;
}
}
}
add_action( 'template_redirect', 'na_redirect_slug_requests', 10, 50 );
Just remember to replace “events” with your custom post type slug.
Related Posts:
- Add .html extension to custom post type taxonomies
- Write to / remove from default .htaccess file from plugin?
- how to change the verification url of pie register plugin of wordpress?
- admin-ajax.php warning max input vars exceeded on layered pop plugins [closed]
- Redirect to another page using contact form 7? [closed]
- WordPress add_rewrite_rules for custom URLs ending in .html
- Edit Permalink Structure For Custom Post Type or Modify .htaccess?
- Custom url rewriting
- WordPress rewrite rules not working
- Do rewrites added with add_rewrite_rule() persist after plugin deletion?
- add_rewrite_rule to load different page, without changing URL in browser
- Add a parameter at the end of the url and prettify
- WordPress rewrite rule depend on meta values not ids
- WP Migrate DB Pro plugin cannot transfer Media files to remote server
- Change custom rewrite rule when permalink is updated/changed
- URL Rewrite 404
- .htaccess file doesn’t work, with hundred tries
- How To Rewrite WordPress Pages URL Only?
- custom url with custom post
- Apache rewrite rules and wordpress problem
- Please Check this ‘.htaccess’ File
- Allow direct access to files/folders within WordPress to replace wp-admin
- How to rewrite URL using .htaccess in WordPress Plugin
- Uncaught Error: Call to undefined function wp_generate_attachment_metadata() @ wp-cron
- When unit testing a plugin, does the plugin need to be in the wp-content/plugins directory of the WordPress tests install?
- How can I prevent a plugin from updating unless it’s minimum PHP version is met?
- Using require_once in a Plugin?
- Stackoverflow type of badge plugin giving warnings in WordPress 3.5
- Plugin.php: PHP Notice: Undefined offset: 0 in
- How Restrict access to admin dashboard by specific static ip?
- htaccess and wordpress config files are regularly over written
- How to get images from EDD post?
- Add multiple attributes to product from php
- Sanitizing, Validating and Escaping in WordPress (Plugin)
- How to initialize something in unit test before the init hook being called?
- Add category to body class
- Plugin Development sqlite or WordPress’ database
- How to review WordPress website php version compatibility?
- WooCommerce get_price returning wrong price when used via ajax
- Open Post Thumbnail in New Child Theme File in WordPress
- Pulling data from custom plugin settings using PHP shortcode and Javascript
- woocommerce 3.2.1 not sending order notification emails
- WordPress on AWS with ELB
- How to access data in wordpress database externally using php
- Add a CSS class based on categroy id to archive pages
- WooCommerce: Building a page with user input which is used to query order status and external API and return a result
- Access WordPress data from external PHP application.
- Problem with PHP wordpress, Undefined index: in C:\xampp\htdocs\wordpress\wp-content\plugins\epoch\classes\core.php on line 190 [closed]
- Reoccurring 404 Errors on all subpages
- After upgrade to php 7 plugin/them updates broke [closed]
- WP Plugins – Use includes to display page content
- WordPress 4.8.1 php getting commented
- Finding the screen id of a page generated with add_menu_page
- Issue running db create table query from static method
- Locked out of admin panel after installing HC Custom WP-Admin URL [closed]
- Use $variable from file1.php in file2.php (different file paths)
- Control page content visibility based on URL parameter
- WooCommerce Shopping Cart Not Initially Showing Products [closed]
- Plugin not working & permalink erorr after upgrade to php 7x on Nginx
- How to include a custom field in the woocommerce email?
- How to translate wordpress error message
- Override a Plugin Function
- All custom widgets are not showing in widget area at the same time
- Add key and value to an array in another file
- Wierd site output [closed]
- Create “new pages” within the admin section of plugin
- More gentle way to hook WordPress custom url
- How to Call Specific .PHP file on add_submenu_page selection in Plugin Development?
- How to properly replace the_content with the html in a php file?
- How to Add text value in Automatically in this conditions?
- Creating an array from form inputs before it is posted to the options database
- Plugin which unlock free gift when you reach some amount in cart
- Problem with Date translation in WordPress
- How to assign a specific service to a specific provider based on location
- How can I create a secure file download in WordPress?
- 500 Internal server error wp_handle_upload_prefilter
- Woocommerce – Change variations output
- WordPress Plugin PHP Not Calling Function
- load plugin in code snippet
- Is admin section completely customizable in terms of styling?
- How to echo meta_key in easy digital downloads receipt (Purchase Confirmation page)
- Plugin error “array_key_exists(): The first argument should be either a string or an integer” [closed]
- I want add repository theme folder
- Migrating custom php we wrote from functions.php into a site-specific plugin
- What is the correct entry point for capturing coverage data
- Change default url to plugin custom post type
- plugins_loaded action is not working properly
- Creating a user ‘add custom field’ section
- How to Set Limit with WordPress Get Bookmarks Shortcode
- Postal address auto-complete on profile page
- avatar displays outside of targeted area
- WordPress Related Plugin – Adding an image
- ACF: Hide a div or template section when a custom field (in a field group) is empty
- How to delete remain data in WP database after deleting custom post via admin interface
- Populate Woocommerce order notes with custom field value
- Woocommerce Product Add-ons – Auto-select first option
- Strict Standards: Non-static method in sidebar generator
- Function not being called on form submit, only blank admin-post.php page
- WordPress Convert queries to slashes using function.php
- plugin doesn’t retrieve data from database