get_edit_post_link

The timeline below displays how wordpress function get_edit_post_link has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Retrieves the edit post link for post.
 *
 * Can be used within the WordPress loop or outside of it. Can be used with
 * pages, posts, attachments, revisions, global styles, templates, and template parts.
 *
 * @since 2.3.0
 * @since 6.3.0 Adds custom link for wp_navigation post types.
 *              Adds custom links for wp_template_part and wp_template post types.
 *
 * @param int|WP_Post $post    Optional. Post ID or post object. Default is the global `$post`.
 * @param string      $context Optional. How to output the '&' character. Default '&'.
 * @return string|null The edit post link for the given post. Null if the post type does not exist
 *                     or does not allow an editing UI.
 */
function get_edit_post_link($post = 0, $context = 'display')
{
    $post = get_post($post);
    if (!$post) {
        return;
    }
    if ('revision' === $post->post_type) {
        $action = '';
    } elseif ('display' === $context) {
        $action = '&action=edit';
    } else {
        $action = '&action=edit';
    }
    $post_type_object = get_post_type_object($post->post_type);
    if (!$post_type_object) {
        return;
    }
    if (!current_user_can('edit_post', $post->ID)) {
        return;
    }
    $link = '';
    if ('wp_template' === $post->post_type || 'wp_template_part' === $post->post_type) {
        $slug = urlencode(get_stylesheet() . '//' . $post->post_name);
        $link = admin_url(sprintf($post_type_object->_edit_link, $post->post_type, $slug));
    } elseif ('wp_navigation' === $post->post_type) {
        $link = admin_url(sprintf($post_type_object->_edit_link, (string) $post->ID));
    } elseif ($post_type_object->_edit_link) {
        $link = admin_url(sprintf($post_type_object->_edit_link . $action, $post->ID));
    }
    /**
     * Filters the post edit link.
     *
     * @since 2.3.0
     *
     * @param string $link    The edit link.
     * @param int    $post_id Post ID.
     * @param string $context The link context. If set to 'display' then ampersands
     *                        are encoded.
     */
    return apply_filters('get_edit_post_link', $link, $post->ID, $context);
}

WordPress Version: 6.1

/**
 * Retrieves the edit post link for post.
 *
 * Can be used within the WordPress loop or outside of it. Can be used with
 * pages, posts, attachments, and revisions.
 *
 * @since 2.3.0
 *
 * @param int|WP_Post $post    Optional. Post ID or post object. Default is the global `$post`.
 * @param string      $context Optional. How to output the '&' character. Default '&'.
 * @return string|null The edit post link for the given post. Null if the post type does not exist
 *                     or does not allow an editing UI.
 */
function get_edit_post_link($post = 0, $context = 'display')
{
    $post = get_post($post);
    if (!$post) {
        return;
    }
    if ('revision' === $post->post_type) {
        $action = '';
    } elseif ('display' === $context) {
        $action = '&action=edit';
    } else {
        $action = '&action=edit';
    }
    $post_type_object = get_post_type_object($post->post_type);
    if (!$post_type_object) {
        return;
    }
    if (!current_user_can('edit_post', $post->ID)) {
        return;
    }
    if ($post_type_object->_edit_link) {
        $link = admin_url(sprintf($post_type_object->_edit_link . $action, $post->ID));
    } else {
        $link = '';
    }
    /**
     * Filters the post edit link.
     *
     * @since 2.3.0
     *
     * @param string $link    The edit link.
     * @param int    $post_id Post ID.
     * @param string $context The link context. If set to 'display' then ampersands
     *                        are encoded.
     */
    return apply_filters('get_edit_post_link', $link, $post->ID, $context);
}

WordPress Version: 5.6

/**
 * Retrieves the edit post link for post.
 *
 * Can be used within the WordPress loop or outside of it. Can be used with
 * pages, posts, attachments, and revisions.
 *
 * @since 2.3.0
 *
 * @param int|WP_Post $id      Optional. Post ID or post object. Default is the global `$post`.
 * @param string      $context Optional. How to output the '&' character. Default '&'.
 * @return string|null The edit post link for the given post. Null if the post type does not exist
 *                     or does not allow an editing UI.
 */
function get_edit_post_link($id = 0, $context = 'display')
{
    $post = get_post($id);
    if (!$post) {
        return;
    }
    if ('revision' === $post->post_type) {
        $action = '';
    } elseif ('display' === $context) {
        $action = '&action=edit';
    } else {
        $action = '&action=edit';
    }
    $post_type_object = get_post_type_object($post->post_type);
    if (!$post_type_object) {
        return;
    }
    if (!current_user_can('edit_post', $post->ID)) {
        return;
    }
    if ($post_type_object->_edit_link) {
        $link = admin_url(sprintf($post_type_object->_edit_link . $action, $post->ID));
    } else {
        $link = '';
    }
    /**
     * Filters the post edit link.
     *
     * @since 2.3.0
     *
     * @param string $link    The edit link.
     * @param int    $post_id Post ID.
     * @param string $context The link context. If set to 'display' then ampersands
     *                        are encoded.
     */
    return apply_filters('get_edit_post_link', $link, $post->ID, $context);
}

WordPress Version: 5.5

/**
 * Retrieves the edit post link for post.
 *
 * Can be used within the WordPress loop or outside of it. Can be used with
 * pages, posts, attachments, and revisions.
 *
 * @since 2.3.0
 *
 * @param int|WP_Post $id      Optional. Post ID or post object. Default is the global `$post`.
 * @param string      $context Optional. How to output the '&' character. Default '&'.
 * @return string|null The edit post link for the given post. null if the post type is invalid or does
 *                     not allow an editing UI.
 */
function get_edit_post_link($id = 0, $context = 'display')
{
    $post = get_post($id);
    if (!$post) {
        return;
    }
    if ('revision' === $post->post_type) {
        $action = '';
    } elseif ('display' === $context) {
        $action = '&action=edit';
    } else {
        $action = '&action=edit';
    }
    $post_type_object = get_post_type_object($post->post_type);
    if (!$post_type_object) {
        return;
    }
    if (!current_user_can('edit_post', $post->ID)) {
        return;
    }
    if ($post_type_object->_edit_link) {
        $link = admin_url(sprintf($post_type_object->_edit_link . $action, $post->ID));
    } else {
        $link = '';
    }
    /**
     * Filters the post edit link.
     *
     * @since 2.3.0
     *
     * @param string $link    The edit link.
     * @param int    $post_id Post ID.
     * @param string $context The link context. If set to 'display' then ampersands
     *                        are encoded.
     */
    return apply_filters('get_edit_post_link', $link, $post->ID, $context);
}

WordPress Version: 5.3

/**
 * Retrieves the edit post link for post.
 *
 * Can be used within the WordPress loop or outside of it. Can be used with
 * pages, posts, attachments, and revisions.
 *
 * @since 2.3.0
 *
 * @param int|WP_Post $id      Optional. Post ID or post object. Default is the global `$post`.
 * @param string      $context Optional. How to output the '&' character. Default '&'.
 * @return string|null The edit post link for the given post. null if the post type is invalid or does
 *                     not allow an editing UI.
 */
function get_edit_post_link($id = 0, $context = 'display')
{
    $post = get_post($id);
    if (!$post) {
        return;
    }
    if ('revision' === $post->post_type) {
        $action = '';
    } elseif ('display' == $context) {
        $action = '&action=edit';
    } else {
        $action = '&action=edit';
    }
    $post_type_object = get_post_type_object($post->post_type);
    if (!$post_type_object) {
        return;
    }
    if (!current_user_can('edit_post', $post->ID)) {
        return;
    }
    if ($post_type_object->_edit_link) {
        $link = admin_url(sprintf($post_type_object->_edit_link . $action, $post->ID));
    } else {
        $link = '';
    }
    /**
     * Filters the post edit link.
     *
     * @since 2.3.0
     *
     * @param string $link    The edit link.
     * @param int    $post_id Post ID.
     * @param string $context The link context. If set to 'display' then ampersands
     *                        are encoded.
     */
    return apply_filters('get_edit_post_link', $link, $post->ID, $context);
}

WordPress Version: 4.9

/**
 * Retrieves the edit post link for post.
 *
 * Can be used within the WordPress loop or outside of it. Can be used with
 * pages, posts, attachments, and revisions.
 *
 * @since 2.3.0
 *
 * @param int|WP_Post $id      Optional. Post ID or post object. Default is the global `$post`.
 * @param string      $context Optional. How to output the '&' character. Default '&'.
 * @return string|null The edit post link for the given post. null if the post type is invalid or does
 *                     not allow an editing UI.
 */
function get_edit_post_link($id = 0, $context = 'display')
{
    if (!$post = get_post($id)) {
        return;
    }
    if ('revision' === $post->post_type) {
        $action = '';
    } elseif ('display' == $context) {
        $action = '&action=edit';
    } else {
        $action = '&action=edit';
    }
    $post_type_object = get_post_type_object($post->post_type);
    if (!$post_type_object) {
        return;
    }
    if (!current_user_can('edit_post', $post->ID)) {
        return;
    }
    if ($post_type_object->_edit_link) {
        $link = admin_url(sprintf($post_type_object->_edit_link . $action, $post->ID));
    } else {
        $link = '';
    }
    /**
     * Filters the post edit link.
     *
     * @since 2.3.0
     *
     * @param string $link    The edit link.
     * @param int    $post_id Post ID.
     * @param string $context The link context. If set to 'display' then ampersands
     *                        are encoded.
     */
    return apply_filters('get_edit_post_link', $link, $post->ID, $context);
}

WordPress Version: 4.6

/**
 * Retrieves the edit post link for post.
 *
 * Can be used within the WordPress loop or outside of it. Can be used with
 * pages, posts, attachments, and revisions.
 *
 * @since 2.3.0
 *
 * @param int    $id      Optional. Post ID. Default is the ID of the global `$post`.
 * @param string $context Optional. How to output the '&' character. Default '&'.
 * @return string|null The edit post link for the given post. null if the post type is invalid or does
 *                     not allow an editing UI.
 */
function get_edit_post_link($id = 0, $context = 'display')
{
    if (!$post = get_post($id)) {
        return;
    }
    if ('revision' === $post->post_type) {
        $action = '';
    } elseif ('display' == $context) {
        $action = '&action=edit';
    } else {
        $action = '&action=edit';
    }
    $post_type_object = get_post_type_object($post->post_type);
    if (!$post_type_object) {
        return;
    }
    if (!current_user_can('edit_post', $post->ID)) {
        return;
    }
    if ($post_type_object->_edit_link) {
        $link = admin_url(sprintf($post_type_object->_edit_link . $action, $post->ID));
    } else {
        $link = '';
    }
    /**
     * Filters the post edit link.
     *
     * @since 2.3.0
     *
     * @param string $link    The edit link.
     * @param int    $post_id Post ID.
     * @param string $context The link context. If set to 'display' then ampersands
     *                        are encoded.
     */
    return apply_filters('get_edit_post_link', $link, $post->ID, $context);
}

WordPress Version: 4.4

/**
 * Retrieve edit posts link for post.
 *
 * Can be used within the WordPress loop or outside of it. Can be used with
 * pages, posts, attachments, and revisions.
 *
 * @since 2.3.0
 *
 * @param int    $id      Optional. Post ID.
 * @param string $context Optional, defaults to display. How to write the '&', defaults to '&'.
 * @return string|null The edit post link for the given post. null if the post type is invalid or does
 *                     not allow an editing UI.
 */
function get_edit_post_link($id = 0, $context = 'display')
{
    if (!$post = get_post($id)) {
        return;
    }
    if ('revision' === $post->post_type) {
        $action = '';
    } elseif ('display' == $context) {
        $action = '&action=edit';
    } else {
        $action = '&action=edit';
    }
    $post_type_object = get_post_type_object($post->post_type);
    if (!$post_type_object) {
        return;
    }
    if (!current_user_can('edit_post', $post->ID)) {
        return;
    }
    if ($post_type_object->_edit_link) {
        $link = admin_url(sprintf($post_type_object->_edit_link . $action, $post->ID));
    } else {
        $link = '';
    }
    /**
     * Filter the post edit link.
     *
     * @since 2.3.0
     *
     * @param string $link    The edit link.
     * @param int    $post_id Post ID.
     * @param string $context The link context. If set to 'display' then ampersands
     *                        are encoded.
     */
    return apply_filters('get_edit_post_link', $link, $post->ID, $context);
}

WordPress Version: 4.3

/**
 * Retrieve edit posts link for post.
 *
 * Can be used within the WordPress loop or outside of it. Can be used with
 * pages, posts, attachments, and revisions.
 *
 * @since 2.3.0
 *
 * @param int    $id      Optional. Post ID.
 * @param string $context Optional, defaults to display. How to write the '&', defaults to '&'.
 * @return string|void The edit post link for the given post.
 */
function get_edit_post_link($id = 0, $context = 'display')
{
    if (!$post = get_post($id)) {
        return;
    }
    if ('revision' === $post->post_type) {
        $action = '';
    } elseif ('display' == $context) {
        $action = '&action=edit';
    } else {
        $action = '&action=edit';
    }
    $post_type_object = get_post_type_object($post->post_type);
    if (!$post_type_object) {
        return;
    }
    if (!current_user_can('edit_post', $post->ID)) {
        return;
    }
    /**
     * Filter the post edit link.
     *
     * @since 2.3.0
     *
     * @param string $link    The edit link.
     * @param int    $post_id Post ID.
     * @param string $context The link context. If set to 'display' then ampersands
     *                        are encoded.
     */
    return apply_filters('get_edit_post_link', admin_url(sprintf($post_type_object->_edit_link . $action, $post->ID)), $post->ID, $context);
}

WordPress Version: 4.1

/**
 * Retrieve edit posts link for post.
 *
 * Can be used within the WordPress loop or outside of it. Can be used with
 * pages, posts, attachments, and revisions.
 *
 * @since 2.3.0
 *
 * @param int $id Optional. Post ID.
 * @param string $context Optional, defaults to display. How to write the '&', defaults to '&'.
 * @return string The edit post link for the given post.
 */
function get_edit_post_link($id = 0, $context = 'display')
{
    if (!$post = get_post($id)) {
        return;
    }
    if ('revision' === $post->post_type) {
        $action = '';
    } elseif ('display' == $context) {
        $action = '&action=edit';
    } else {
        $action = '&action=edit';
    }
    $post_type_object = get_post_type_object($post->post_type);
    if (!$post_type_object) {
        return;
    }
    if (!current_user_can('edit_post', $post->ID)) {
        return;
    }
    /**
     * Filter the post edit link.
     *
     * @since 2.3.0
     *
     * @param string $link    The edit link.
     * @param int    $post_id Post ID.
     * @param string $context The link context. If set to 'display' then ampersands
     *                        are encoded.
     */
    return apply_filters('get_edit_post_link', admin_url(sprintf($post_type_object->_edit_link . $action, $post->ID)), $post->ID, $context);
}

WordPress Version: 3.9

/**
 * Retrieve edit posts link for post.
 *
 * Can be used within the WordPress loop or outside of it. Can be used with
 * pages, posts, attachments, and revisions.
 *
 * @since 2.3.0
 *
 * @param int $id Optional. Post ID.
 * @param string $context Optional, defaults to display. How to write the '&', defaults to '&'.
 * @return string
 */
function get_edit_post_link($id = 0, $context = 'display')
{
    if (!$post = get_post($id)) {
        return;
    }
    if ('revision' === $post->post_type) {
        $action = '';
    } elseif ('display' == $context) {
        $action = '&action=edit';
    } else {
        $action = '&action=edit';
    }
    $post_type_object = get_post_type_object($post->post_type);
    if (!$post_type_object) {
        return;
    }
    if (!current_user_can('edit_post', $post->ID)) {
        return;
    }
    /**
     * Filter the post edit link.
     *
     * @since 2.3.0
     *
     * @param string $link    The edit link.
     * @param int    $post_id Post ID.
     * @param string $context The link context. If set to 'display' then ampersands
     *                        are encoded.
     */
    return apply_filters('get_edit_post_link', admin_url(sprintf($post_type_object->_edit_link . $action, $post->ID)), $post->ID, $context);
}

WordPress Version: 3.7

/**
 * Retrieve edit posts link for post.
 *
 * Can be used within the WordPress loop or outside of it. Can be used with
 * pages, posts, attachments, and revisions.
 *
 * @since 2.3.0
 *
 * @param int $id Optional. Post ID.
 * @param string $context Optional, defaults to display. How to write the '&', defaults to '&'.
 * @return string
 */
function get_edit_post_link($id = 0, $context = 'display')
{
    if (!$post = get_post($id)) {
        return;
    }
    if ('revision' === $post->post_type) {
        $action = '';
    } elseif ('display' == $context) {
        $action = '&action=edit';
    } else {
        $action = '&action=edit';
    }
    $post_type_object = get_post_type_object($post->post_type);
    if (!$post_type_object) {
        return;
    }
    if (!current_user_can('edit_post', $post->ID)) {
        return;
    }
    return apply_filters('get_edit_post_link', admin_url(sprintf($post_type_object->_edit_link . $action, $post->ID)), $post->ID, $context);
}