Skip to content

Instantly share code, notes, and snippets.

@JiveDig
Last active September 16, 2020 19:14
Show Gist options
  • Save JiveDig/9861e8d6eb955f29cea9 to your computer and use it in GitHub Desktop.
Save JiveDig/9861e8d6eb955f29cea9 to your computer and use it in GitHub Desktop.
Filter WP 'Edit Post' link to go to front end /edit-post/ page with ?post_id=123 query arg to allow editing posts via the front end
<?php
/**
* Filter WP 'Edit Post' link to go to front end /edit-post/ page
*
* @author Mike Hemberger
* @link http://thestizmedia.com/front-end-post-editing-with-caldera-forms/
* @return string url to front end for with query arg source post ID ( ?post_id=123 )
*/
add_filter( 'get_edit_post_link', 'tsm_edit_post_link', 10, 1 );
function tsm_edit_post_link( $url ) {
// Bail if user is an admin so links will still go to Dashbaord
if ( current_user_can('manage_options') ) {
return $url;
}
return esc_url( add_query_arg( 'post_id', get_the_ID(), home_url('/edit-post/') ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment