# Edit Links on Posts in Blog and Archive Lists

> Adds an Edit link under each post on blog, archive and search pages for logged-in users who are allowed to edit that post. Works with classic themes and Query Loop blocks.

- Type: PHP
- Runs: Frontend only
- Category: [Archives](https://wpide.com/library/category/archive/)
- Tags: archive, editing, admin
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/edit-links-in-post-listings/

## Code

```php
// Link text. Screen readers also hear the post title.
$wpide_listing_edit_text = 'Edit';

$wpide_listing_edit_link = function ( $post_id ) use ( $wpide_listing_edit_text ) {
    $url = get_edit_post_link( $post_id, 'raw' );

    if ( ! $url || ! current_user_can( 'edit_post', $post_id ) ) {
        return '';
    }

    $label = $wpide_listing_edit_text . ' “' . wp_strip_all_tags( get_the_title( $post_id ) ) . '”';

    return '<p class="wpide-edit-link"><a class="post-edit-link" href="' . esc_url( $url ) . '" aria-label="' . esc_attr( $label ) . '">' . esc_html( $wpide_listing_edit_text ) . '</a></p>';
};

// Classic themes: after the excerpt or content of each post on blog, archive and search pages.
$wpide_listing_edit_append = function ( $content ) use ( $wpide_listing_edit_link ) {
    if ( is_admin() || is_feed() || is_singular() || wp_is_block_theme() || ! in_the_loop() || doing_filter( 'get_the_excerpt' ) ) {
        return $content;
    }

    return $content . $wpide_listing_edit_link( get_the_ID() );
};

add_filter( 'the_excerpt', $wpide_listing_edit_append, 20 );
add_filter( 'the_content', $wpide_listing_edit_append, 20 );

// Block themes: after the Post Title block inside any Query Loop.
add_filter( 'render_block_core/post-title', function ( $content, $block, $instance = null ) use ( $wpide_listing_edit_link ) {
    if ( is_admin() || ! $instance instanceof WP_Block || empty( $instance->context['postId'] ) || ! isset( $instance->context['queryId'] ) ) {
        return $content;
    }

    return $content . $wpide_listing_edit_link( (int) $instance->context['postId'] );
}, 10, 3 );
```

## Notes

Visitors never see the link. In block themes it appears after the Post Title block of each item in a Query Loop. Some classic themes already print an edit link in the post footer; if yours does, you will see both.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Edit Links on Posts in Blog and Archive Lists" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
