Implementation notes:
-
You need to use that function with an appropriate action hook. For example,
template_redirect
hook can be used here. -
If you want URL to have
?edit
, thenempty
check is not necessary, if you want URL to have something like?edit=1
, then use! empty
check. -
Check and ignore if we are already on the
admin
pages. -
Check and proceed if we are on a single
post
page.
CODE:
Following is an example code that’ll work:
function fyz_edit_redirect() {
if( ! is_admin() // skip if we are on admin pages already
&& is_single() // apply only if it's a single post
&& isset( $_GET['edit'] ) && ! empty( $_GET['edit'] ) ) {
wp_safe_redirect( admin_url( '/post.php?action=edit&post=" . get_the_ID() ) );
exit;
}
}
add_action( "template_redirect', 'fyz_edit_redirect' );
Related Posts:
- send popup after wp_redirect()
- WordPress – Get Posts with Category data
- no_rest_route error on custom routes
- Add a custom WooCommerce settings tab with sections
- Flatten Responses returned via WP REST API via WP_Error for obfuscation
- How to use wp_send_json() and output the value with ajax?
- How does add_option() function enable action hooks to fire right after actiavtion?
- How to correctly escape an echo
- PHP using external anonymous function inside class
- Ajax on the Administration Side of plugin – wp_localize_script – how to pass value from JQuery to PHP function in class?
- Problem with inserting multiple images in gallery of each WooCommerce product programmatically
- Is it possible to access admin-ajax.php using PHP?
- Payment field disappears on custom Paypal plugin
- Call to “admin_notices” hook from a static method
- How to Create custom block for displaying information in content section which act like shortcode
- Using ACF Relationship field to set post type to draft or published status
- Adding image upload in tag section – WordPress plugin development
- How to detect and handle the time difference between server and user in WordPress?
- Create plugin with custom page and template caused an error `Call to undefined function get_header()`
- How to Remove Theme Style CSS inside Custom Plugin?
- WordPress can’t use ZipArchive
- How to setup the Email piping in WordPress plugin?
- Create ACF Checkbox to get all ACF Values from Parent Page
- Settings API form – submit with AJAX
- Custom Login page, redirection and restrictions
- How to extend SelectControl with data from my theme
- How to change basename url for wp-admin?
- Post form – AJAX won’t upload featured image – Plugin development
- Creating plugin with front-end pages
- How to Send Pingbacks for all Posts in WordPress?
- Reliable way to add nonce to HTTP Header in WordPress?
- random post redirect in wordpress with a .php file
- I am having errors with checkout on wordpress
- Only the first image uploads
- Getting an error when my plugin is updated, but the files update correctly
- WordPress loading progess – wp-blog-header.php
- Creating a POP Alert
- Add Pre-Defined Value to Click Counter in WordPress
- Illegal string offset checkbox
- Implementing a multilingual WordPress site by installing several instances of WordPress and redirecting
- File is executed twice if plugin is activating
- ssl redirect function is not working
- product_type_options get saved value [closed]
- Custom plugin: how do I call a PHP file if settings option is set to true?
- Plugin won’t output characters with diacritics properly
- Trying to use a variable to set image width
- How can i avoid duplicate same post in wp?
- Drop down question
- Display a custom name when the user has no name settle in his account
- wp_update_post gives 500 internal error
- WP Hook Before a post is created
- WordPress Plugin Development – get_option error
- how to add new PHP page in WordPress plugin
- How do I disable cache for a certain page?
- How can I get my WordPress plugin to receive data and relay it in an ajax/php request to a remote server that requires authentication?
- code that I can run, or a plug in to show what sql tables something pulls information from
- Automatic email message after manual user approval
- How can I update the price when someone enters postcode or zip code in woocommerce checkout page?
- Submit remote form to wordpress REST API and save data to custom post type
- How to check if plugin update process completed in wordpress?
- Foreach Loop Of Post Types With Nested If Else If Not Completing Process
- ACF relationship on user profile page used for allowed access
- How to identify which php file a plugin is using on page load?
- dashboard widget form not submit mails
- In a foreach loop, how can I add a meta value if it doesn’t exist?
- Looping through and combining calls to Woocommerce REST API
- Should I use wp_cache in my plugin to make it faster?
- custom mailchimp form using HTTP API
- How to override theme’s public static function inside of a trait?
- pass datetime using wp_localize_script to frontend from settings page
- register_setting not save checkbox
- add custom metabox to media library custom widget
- using filter and hook inside class
- 400 bad request admin-ajax file upload
- Store user form submitted information in post type
- Constant expression contains invalid operations plugin class properties visibility
- How to import woocommerce custom fields data into another site?
- get Woocommerce product format json for WP_Query
- Display attached images of a page or post that are insetred using gallery
- overwrite wordpress gallery with custom gallery shortcode
- Add a custom link to each image in WordPress gallery
- Gutenberg blocks shortcodes compatibility
- Enqueue sripts and styles only if function is called
- Problem with my Login Plugin
- Add widget area from visual editor
- Save custom field on WP_List_Table
- How to access this jQuery/AJAX data in a PHP file/WordPress plugin
- How to return html as a string from php for WordPress
- Load script and styles using an array of resources
- Register/enqueue scripts only on certain admin pages
- post_exists stops working in a scheduled event
- Looping through custom data in a custom table to display all items in a post
- register dependency css and js inside a plugin class
- Sum All the Post Meta of Published posts of Current Logged in user
- Update user meta when an external link in admin notice is clicked
- Is there an option to execute javascript file only on plugin activation
- When I create a new custom post type, it replaces the old post type
- How do I remove an action hook inside a class that is called by another class?
- How does one make a URL return dynamic JSON with custom Content Type?
- How to give custom roles the capability to edit one Menu instead of every Menu