How to add quick edit button on front end

PHP Code Snippets/Functions

Requirements:

  • functions.php

In this tutorial i will teach you how to add a quick edit link at the top of you admin panel in your front end.

Step 1: copy the links below in your functions.php

function add_quick_edit_link() {
    // print_r(current_user_can('administrator'));
    if ( ! current_user_can('administrator') && ! current_user_can('editor') ) {
     return;
    }

    

    global $post;
    $post_id = ($post->ID == 0 || $post->ID == null) ? " " : $post_id;
    $edit_link = html_entity_decode(get_edit_post_link($post_id));
    // print_r("I'm here: ".$edit_link);

    ?>
    <script type="text/javascript">
        jQuery(document).ready(function($) {
            var editLink = $('<a></a>');
            editLink.attr('href', '<?php echo $edit_link; ?>');
            editLink.text('Quick Edit');
            editLink.css({
                'float': 'right',
                'backgroundColor': '#fff',
                'border': '1px solid #ccc'
            });

            $('#wpadminbar .quicklinks').prepend(editLink);
        });
    </script>
    <?php
}

add_action('wp_footer', 'add_quick_edit_link');

note: if you want to add stylings to you quick link button, just add some css code to your css files.

That’s all for this tutorial, Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *