edit_post_link

The timeline below displays how wordpress function 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.2

/**
 * Displays the edit post link for post.
 *
 * @since 1.0.0
 * @since 4.4.0 The `$css_class` argument was added.
 *
 * @param string      $text      Optional. Anchor text. If null, default is 'Edit This'. Default null.
 * @param string      $before    Optional. Display before edit link. Default empty.
 * @param string      $after     Optional. Display after edit link. Default empty.
 * @param int|WP_Post $post      Optional. Post ID or post object. Default is the global `$post`.
 * @param string      $css_class Optional. Add custom class to link. Default 'post-edit-link'.
 */
function edit_post_link($text = null, $before = '', $after = '', $post = 0, $css_class = 'post-edit-link')
{
    $post = get_post($post);
    if (!$post) {
        return;
    }
    $url = get_edit_post_link($post->ID);
    if (!$url) {
        return;
    }
    if (null === $text) {
        $text = __('Edit This');
    }
    $link = '<a class="' . esc_attr($css_class) . '" href="' . esc_url($url) . '">' . $text . '</a>';
    /**
     * Filters the post edit link anchor tag.
     *
     * @since 2.3.0
     *
     * @param string $link    Anchor tag for the edit link.
     * @param int    $post_id Post ID.
     * @param string $text    Anchor text.
     */
    echo $before . apply_filters('edit_post_link', $link, $post->ID, $text) . $after;
}

WordPress Version: 6.1

/**
 * Displays the edit post link for post.
 *
 * @since 1.0.0
 * @since 4.4.0 The `$class` argument was added.
 *
 * @param string      $text   Optional. Anchor text. If null, default is 'Edit This'. Default null.
 * @param string      $before Optional. Display before edit link. Default empty.
 * @param string      $after  Optional. Display after edit link. Default empty.
 * @param int|WP_Post $post   Optional. Post ID or post object. Default is the global `$post`.
 * @param string      $class  Optional. Add custom class to link. Default 'post-edit-link'.
 */
function edit_post_link($text = null, $before = '', $after = '', $post = 0, $class = 'post-edit-link')
{
    $post = get_post($post);
    if (!$post) {
        return;
    }
    $url = get_edit_post_link($post->ID);
    if (!$url) {
        return;
    }
    if (null === $text) {
        $text = __('Edit This');
    }
    $link = '<a class="' . esc_attr($class) . '" href="' . esc_url($url) . '">' . $text . '</a>';
    /**
     * Filters the post edit link anchor tag.
     *
     * @since 2.3.0
     *
     * @param string $link    Anchor tag for the edit link.
     * @param int    $post_id Post ID.
     * @param string $text    Anchor text.
     */
    echo $before . apply_filters('edit_post_link', $link, $post->ID, $text) . $after;
}

WordPress Version: 5.3

/**
 * Displays the edit post link for post.
 *
 * @since 1.0.0
 * @since 4.4.0 The `$class` argument was added.
 *
 * @param string      $text   Optional. Anchor text. If null, default is 'Edit This'. Default null.
 * @param string      $before Optional. Display before edit link. Default empty.
 * @param string      $after  Optional. Display after edit link. Default empty.
 * @param int|WP_Post $id     Optional. Post ID or post object. Default is the global `$post`.
 * @param string      $class  Optional. Add custom class to link. Default 'post-edit-link'.
 */
function edit_post_link($text = null, $before = '', $after = '', $id = 0, $class = 'post-edit-link')
{
    $post = get_post($id);
    if (!$post) {
        return;
    }
    $url = get_edit_post_link($post->ID);
    if (!$url) {
        return;
    }
    if (null === $text) {
        $text = __('Edit This');
    }
    $link = '<a class="' . esc_attr($class) . '" href="' . esc_url($url) . '">' . $text . '</a>';
    /**
     * Filters the post edit link anchor tag.
     *
     * @since 2.3.0
     *
     * @param string $link    Anchor tag for the edit link.
     * @param int    $post_id Post ID.
     * @param string $text    Anchor text.
     */
    echo $before . apply_filters('edit_post_link', $link, $post->ID, $text) . $after;
}

WordPress Version: 4.9

/**
 * Displays the edit post link for post.
 *
 * @since 1.0.0
 * @since 4.4.0 The `$class` argument was added.
 *
 * @param string      $text   Optional. Anchor text. If null, default is 'Edit This'. Default null.
 * @param string      $before Optional. Display before edit link. Default empty.
 * @param string      $after  Optional. Display after edit link. Default empty.
 * @param int|WP_Post $id     Optional. Post ID or post object. Default is the global `$post`.
 * @param string      $class  Optional. Add custom class to link. Default 'post-edit-link'.
 */
function edit_post_link($text = null, $before = '', $after = '', $id = 0, $class = 'post-edit-link')
{
    if (!$post = get_post($id)) {
        return;
    }
    if (!$url = get_edit_post_link($post->ID)) {
        return;
    }
    if (null === $text) {
        $text = __('Edit This');
    }
    $link = '<a class="' . esc_attr($class) . '" href="' . esc_url($url) . '">' . $text . '</a>';
    /**
     * Filters the post edit link anchor tag.
     *
     * @since 2.3.0
     *
     * @param string $link    Anchor tag for the edit link.
     * @param int    $post_id Post ID.
     * @param string $text    Anchor text.
     */
    echo $before . apply_filters('edit_post_link', $link, $post->ID, $text) . $after;
}

WordPress Version: 4.6

/**
 * Displays the edit post link for post.
 *
 * @since 1.0.0
 * @since 4.4.0 The `$class` argument was added.
 *
 * @param string $text   Optional. Anchor text. If null, default is 'Edit This'. Default null.
 * @param string $before Optional. Display before edit link. Default empty.
 * @param string $after  Optional. Display after edit link. Default empty.
 * @param int    $id     Optional. Post ID. Default is the ID of the global `$post`.
 * @param string $class  Optional. Add custom class to link. Default 'post-edit-link'.
 */
function edit_post_link($text = null, $before = '', $after = '', $id = 0, $class = 'post-edit-link')
{
    if (!$post = get_post($id)) {
        return;
    }
    if (!$url = get_edit_post_link($post->ID)) {
        return;
    }
    if (null === $text) {
        $text = __('Edit This');
    }
    $link = '<a class="' . esc_attr($class) . '" href="' . esc_url($url) . '">' . $text . '</a>';
    /**
     * Filters the post edit link anchor tag.
     *
     * @since 2.3.0
     *
     * @param string $link    Anchor tag for the edit link.
     * @param int    $post_id Post ID.
     * @param string $text    Anchor text.
     */
    echo $before . apply_filters('edit_post_link', $link, $post->ID, $text) . $after;
}

WordPress Version: 4.4

/**
 * Display edit post link for post.
 *
 * @since 1.0.0
 * @since 4.4.0 The `$class` argument was added.
 *
 * @param string $text   Optional. Anchor text.
 * @param string $before Optional. Display before edit link.
 * @param string $after  Optional. Display after edit link.
 * @param int    $id     Optional. Post ID.
 * @param string $class  Optional. Add custom class to link.
 */
function edit_post_link($text = null, $before = '', $after = '', $id = 0, $class = 'post-edit-link')
{
    if (!$post = get_post($id)) {
        return;
    }
    if (!$url = get_edit_post_link($post->ID)) {
        return;
    }
    if (null === $text) {
        $text = __('Edit This');
    }
    $link = '<a class="' . esc_attr($class) . '" href="' . esc_url($url) . '">' . $text . '</a>';
    /**
     * Filter the post edit link anchor tag.
     *
     * @since 2.3.0
     *
     * @param string $link    Anchor tag for the edit link.
     * @param int    $post_id Post ID.
     * @param string $text    Anchor text.
     */
    echo $before . apply_filters('edit_post_link', $link, $post->ID, $text) . $after;
}

WordPress Version: 4.3

/**
 * Display edit post link for post.
 *
 * @since 1.0.0
 *
 * @param string $text   Optional. Anchor text.
 * @param string $before Optional. Display before edit link.
 * @param string $after  Optional. Display after edit link.
 * @param int    $id     Optional. Post ID.
 */
function edit_post_link($text = null, $before = '', $after = '', $id = 0)
{
    if (!$post = get_post($id)) {
        return;
    }
    if (!$url = get_edit_post_link($post->ID)) {
        return;
    }
    if (null === $text) {
        $text = __('Edit This');
    }
    $link = '<a class="post-edit-link" href="' . $url . '">' . $text . '</a>';
    /**
     * Filter the post edit link anchor tag.
     *
     * @since 2.3.0
     *
     * @param string $link    Anchor tag for the edit link.
     * @param int    $post_id Post ID.
     * @param string $text    Anchor text.
     */
    echo $before . apply_filters('edit_post_link', $link, $post->ID, $text) . $after;
}

WordPress Version: 4.0

/**
 * Display edit post link for post.
 *
 * @since 1.0.0
 *
 * @param string $text Optional. Anchor text.
 * @param string $before Optional. Display before edit link.
 * @param string $after Optional. Display after edit link.
 * @param int $id Optional. Post ID.
 */
function edit_post_link($text = null, $before = '', $after = '', $id = 0)
{
    if (!$post = get_post($id)) {
        return;
    }
    if (!$url = get_edit_post_link($post->ID)) {
        return;
    }
    if (null === $text) {
        $text = __('Edit This');
    }
    $link = '<a class="post-edit-link" href="' . $url . '">' . $text . '</a>';
    /**
     * Filter the post edit link anchor tag.
     *
     * @since 2.3.0
     *
     * @param string $link    Anchor tag for the edit link.
     * @param int    $post_id Post ID.
     * @param string $text    Anchor text.
     */
    echo $before . apply_filters('edit_post_link', $link, $post->ID, $text) . $after;
}

WordPress Version: 3.9

/**
 * Display edit post link for post.
 *
 * @since 1.0.0
 *
 * @param string $link Optional. Anchor text.
 * @param string $before Optional. Display before edit link.
 * @param string $after Optional. Display after edit link.
 * @param int $id Optional. Post ID.
 */
function edit_post_link($link = null, $before = '', $after = '', $id = 0)
{
    if (!$post = get_post($id)) {
        return;
    }
    if (!$url = get_edit_post_link($post->ID)) {
        return;
    }
    if (null === $link) {
        $link = __('Edit This');
    }
    $post_type_obj = get_post_type_object($post->post_type);
    $link = '<a class="post-edit-link" href="' . $url . '">' . $link . '</a>';
    /**
     * Filter the post edit link anchor tag.
     *
     * @since 2.3.0
     *
     * @param string $link    Anchor tag for the edit link.
     * @param int    $post_id Post ID.
     */
    echo $before . apply_filters('edit_post_link', $link, $post->ID) . $after;
}

WordPress Version: 3.7

/**
 * Display edit post link for post.
 *
 * @since 1.0.0
 *
 * @param string $link Optional. Anchor text.
 * @param string $before Optional. Display before edit link.
 * @param string $after Optional. Display after edit link.
 * @param int $id Optional. Post ID.
 */
function edit_post_link($link = null, $before = '', $after = '', $id = 0)
{
    if (!$post = get_post($id)) {
        return;
    }
    if (!$url = get_edit_post_link($post->ID)) {
        return;
    }
    if (null === $link) {
        $link = __('Edit This');
    }
    $post_type_obj = get_post_type_object($post->post_type);
    $link = '<a class="post-edit-link" href="' . $url . '">' . $link . '</a>';
    echo $before . apply_filters('edit_post_link', $link, $post->ID) . $after;
}