Using WordPress ‘get_default_link_to_edit()’ PHP function

The get_default_link_to_edit() WordPress PHP function retrieves the default link for editing.


$link = get_default_link_to_edit();


  • None

More information

See WordPress Developer Resources: get_default_link_to_edit()


This example will redirect the user to the default edit link after successful login.

function custom_login_redirect($redirect_to, $request, $user) {
    if (is_wp_error($user)) {
        return $redirect_to;

    // Get the default link to edit
    $edit_link = get_default_link_to_edit();

    // Redirect to the default edit link
    return $edit_link;
add_filter('login_redirect', 'custom_login_redirect', 10, 3);

This example will display the default edit link in the theme’s footer.

function display_default_edit_link() {
    $edit_link = get_default_link_to_edit();
    echo '<p><a href="' . $edit_link . '">Edit your content</a></p>';
add_action('wp_footer', 'display_default_edit_link');

This example will add the default edit link to the main navigation menu.

function add_default_edit_link_to_nav($items, $args) {
    if ($args->theme_location == 'primary') {
        $edit_link = get_default_link_to_edit();
        $items .= '<li><a href="' . $edit_link . '">Edit</a></li>';
    return $items;
add_filter('wp_nav_menu_items', 'add_default_edit_link_to_nav', 10, 2);

This example will add the default edit link to the admin bar for quick access.

function add_default_edit_link_to_admin_bar($wp_admin_bar) {
    $edit_link = get_default_link_to_edit();

    $args = array(
        'id' => 'default_edit_link',
        'title' => 'Edit Default Content',
        'href' => $edit_link

add_action('admin_bar_menu', 'add_default_edit_link_to_admin_bar', 90);

This example will create a custom button that takes the user to the default edit link when clicked.

function custom_edit_button_shortcode() {
    $edit_link = get_default_link_to_edit();
    return '<a class="button" href="' . $edit_link . '">Edit Content</a>';
add_shortcode('edit_button', 'custom_edit_button_shortcode');

Use the shortcode [edit_button] in your content to display the custom edit button.