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()
- When to use Exceptions vs Error Objects vs just plain false/null
- Uninstalling a plugin: delete all options with specific prefix
- WordPress URL Rewrite not working
- PHP – redirect https to http and www to non-www
- Display a text message if the shortcode is not found?
- simple wordpress ajax plugin not working when not logged in
- Saving metabox repeatable fields
- Why is PHP Cookie via plugin only set when logged in as Admin and not regular users? and other questions
- how to create and show sessions in word press?
- Loading page template into shortcode
- do not show web page section when using advanced custom fields pro
- How to get all existing post types
- Using wp_get_image_editor in a standalone script
- New Plugin Review
- Create custom blocks for bootstrap
- Query String being Removed Creating a Pagination Issue within a Custom Plugin
- wp_insert_post() is returning the correct post ID, no failure, but the post content does not get updated
- What does $wpdb->get_row return?
- woocommerce subscriptions – get expiration date [closed]
- WordPress Scheduled Event Request Blocking
- Plugin CSS not enqueing
- PHP Fatal error: Uncaught mysqli_sql_exception: Table doesn’t exist in wordpress/wp-includes/wp-db.php
- How to set up VS Code for WP plugin/theme development in 2021? [closed]
- Saving an array of dynamic repeater data as post_meta
- WordPress wpform plugin submit and get multiple checked value from checkbox [closed]
- Improve page speed loading using CDN and async or defer attribute
- How to call plugin function per site in a multisite?
- Script to browser problem PHP
- Store a default value for a transient on plugin activation
- How wp-cron can run in background if PHP is single threaded?
- Options API get_option() and update_option() Not Correctly Updating or Returning
- wp query foreach deleting record returning only first or last item
- PHP > Scheduled Tasks > Sending daily email with dynamic API variables
- How to make own crop image function for WordPress plugin
- WordPress Custom field Colors
- “Undefined index” error when saving empty array with checkboxes
- Is it save to use eval for a jQuery callback method coming from the database?
- Scheduling an event inside plugin class is not working
- How to Change CSS Colors from Custom Plugin Settings Page
- Passing the name of selected color from the custom component to `render_callback`
- Any ideas why I am getting “I’m getting “wp-admin/admin-ajax.php 401 (Unauthorized)”
- Cant register rest routs from class instance
- wordpress frontend editor to add extra css to website
- Logout redirects to default page
- How can I search all plugins for composer’s vendor/autoload.php?
- Action Hook Inside WordPress Plugin Shortcode
- Manually Create PHP Page For A Redirect
- PHP: How to access db the right way in plugin?
- select a single val though a table in wordpress
- Submit form to db
- WordPress – Get Posts with Category data
- How to use wp_send_json() and output the value with ajax?
- PHP using external anonymous function inside class
- Problem with inserting multiple images in gallery of each WooCommerce product programmatically
- Is it possible to access admin-ajax.php using PHP?
- Call to “admin_notices” hook from a static method
- How to Create custom block for displaying information in content section which act like shortcode
- How to detect and handle the time difference between server and user in WordPress?
- How to setup the Email piping in WordPress plugin?
- Reliable way to add nonce to HTTP Header in WordPress?
- Getting an error when my plugin is updated, but the files update correctly
- Creating a POP Alert
- Add Pre-Defined Value to Click Counter in WordPress
- ssl redirect function is not working
- WordPress Plugin Development – get_option error
- how to add new PHP page in WordPress plugin
- 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
- Constant expression contains invalid operations plugin class properties visibility
- Display attached images of a page or post that are insetred using gallery
- overwrite wordpress gallery with custom gallery shortcode
- Gutenberg blocks shortcodes compatibility
- Enqueue sripts and styles only if function is called
- Add widget area from visual editor
- Save custom field on WP_List_Table
- Load script and styles using an array of resources
- Register/enqueue scripts only on certain admin pages
- Looping through custom data in a custom table to display all items in a post
- Input field duplicates on form submit by jQuery
- Custom Plugin Develoment, Form Action
- How to Request a User to Register on Landing at a Site, Then Automatically Delete the Users Password on Logout?
- Unable to pass variable to database
- Gravity Forms Marketo Plugin Feed [closed]
- INCOMING: Wall of code for form and $_POST, not updating custom field’s value
- add shortcode heading showing multiple time
- Add custom filter to register data in array
- WP multisite network plugin fails to see classes loaded with spl autoload
- Trouble using wordpress functions in a pop-up modal form
- MySQL update text field with ‘
- What is this mark for “? function()” [closed]
- how can I make content from a plugin hidden when user is logged in? [duplicate]
- display php code in header using wp_head()
- using a shortcode in a hyperlink
- Login user into magento using wordpress account
- How to pass and validate nonce in custom REST routes
- ajax problems on loading page [closed]
- wp_register_script – illegal string offset
- How can I modify the html output of a custom post type admin page?