Created
October 29, 2014 19:12
-
-
Save hasinhayder/c0f3968129a32df862a5 to your computer and use it in GitHub Desktop.
Redirect WordPress posts to the editor if someone types /edit at the end of the permalink
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function init_url_rewrite_rule(){ | |
add_rewrite_endpoint( 'edit',EP_PERMALINK | EP_PAGES | EP_ATTACHMENT ); | |
if(get_option("EDIT_REWRITE_RULE")!=1){ | |
flush_rewrite_rules(); | |
update_option("EDIT_REWRITE_RULE",1); | |
} | |
} | |
function redirect_edit_url(){ | |
global $wp_query; | |
if(is_single() || is_page() || is_attachment()){ | |
if(isset($wp_query->query_vars['edit'])) { | |
$url = get_edit_post_link(0,'&'); | |
wp_redirect($url); | |
} | |
} | |
} | |
add_action("init","init_url_rewrite_rule"); | |
add_action("template_redirect","redirect_edit_url"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment