Subtle diagonal pinstripe pattern in light grey and cream, giving an impression of printed editorial paper

Add a Read More Button to WordPress Excerpts with Custom HTML

WordPress automatically generates excerpts for many archive pages, including category listings, search results and blog indexes. The default “Read more” link is usually plain text, and its placement or markup may not suit a custom theme, accessibility requirements or a WooCommerce-style content layout.

A small PHP adjustment can replace that text with a button-like link containing custom HTML. The approach works well for classic themes and can be adapted for block themes, provided the code is loaded from a child theme or a site-specific plugin rather than being edited into a parent theme.

For Australian websites, archive pages often need to work across a wide range of devices and connection conditions. A news site serving readers in Sydney, a trades business in Perth or a regional store outside Toowoomba benefits from clear excerpt links that are easy to identify on mobile screens and simple to maintain.

Approach Best for Main benefit Main limitation
excerpt_more filter Standard automatic excerpts Quick replacement of the default link Limited control over excerpt structure
Custom excerpt callback Different layouts or templates Full control of text and markup Requires template changes
get_the_excerpt() with HTML Custom archive cards Flexible reusable output Needs careful escaping
Read more link in template Block or bespoke themes Precise visual placement More dependent on theme structure
Site-specific plugin Long-term maintenance Survives theme changes Requires plugin setup

Choosing the Right Excerpt Hook

The excerpt_more filter is the simplest way to alter the link appended to an automatically generated WordPress excerpt. It receives the default continuation string and allows you to return a custom anchor element. Since an anchor is still used, the result remains semantically correct even when CSS makes it look like a button.

Add the following code to a child theme’s functions.php file or, preferably, a small site-specific plugin:

function wpqa_custom_excerpt_more( $more ) {
    return sprintf(
        ' <a class="read-more-button" href="%s" aria-label="%s">Read more</a>',
        esc_url( get_permalink() ),
        esc_attr( sprintf( 'Read more about %s', get_the_title() ) )
    );
}
add_filter( 'excerpt_more', 'wpqa_custom_excerpt_more' );

The leading space before the link prevents the final word of the excerpt from running into the button. get_permalink() obtains the current post URL, while esc_url() and esc_attr() protect the generated attributes. The contextual aria-label is useful when several archive cards contain identical visible link text.

Adding Custom HTML Safely

A button-style link should remain an HTML anchor because its purpose is navigation. Using a <button> element for a link can create problems for keyboard users, screen readers and browser behaviour. The CSS can provide the visual appearance of a button without changing the meaning of the element.

If the design requires an icon, include it without interfering with the accessible name:

function wpqa_custom_excerpt_more( $more ) {
    $title = get_the_title();

    return sprintf(
        ' <a class="read-more-button" href="%1$s" aria-label="%2$s">
            <span class="read-more-button__text">Read more</span>
            <span class="read-more-button__icon" aria-hidden="true">→</span>
        </a>',
        esc_url( get_permalink() ),
        esc_attr( sprintf( 'Read more about %s', $title ) )
    );
}
add_filter( 'excerpt_more', 'wpqa_custom_excerpt_more' );

The icon is marked aria-hidden="true" because the visible words already explain the action. Avoid placing untrusted post data directly inside HTML. WordPress functions such as esc_html(), esc_attr() and esc_url() should be used according to the context in which each value is printed.

Controlling Excerpt Length and Content

The filter above changes the ending of an excerpt, but it does not control how much content WordPress displays. The default excerpt length is commonly 55 words. A site with compact archive cards may need fewer words, while a long-form publication may need a longer summary.

A global length adjustment can be added with excerpt_length:

function wpqa_archive_excerpt_length( $length ) {
    return 28;
}
add_filter( 'excerpt_length', 'wpqa_archive_excerpt_length', 999 );

This affects automatic excerpts throughout the site, so a conditional callback is often safer. For example, you can return 28 words on the home page and 45 words elsewhere. Before changing the length, check how the excerpt interacts with the grid, featured images and heading sizes. A card that looks balanced on a desktop monitor in Melbourne may become very tall on a narrow phone viewport.

When editors write a manual excerpt in the WordPress editor, WordPress uses that text instead of generating one from the post content. This makes manual excerpts useful for important landing pages, seasonal campaigns and product announcements. The custom read-more link can still be appended, giving editors control over the summary while keeping the call to action consistent.

Styling the Link as a Button

The PHP creates the markup, but CSS controls its appearance. A reusable class makes the component easier to apply across blog archives, search results and related-post areas:

.read-more-button {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 1rem;
    padding: 0.7rem 1rem;
    border: 2px solid #145a72;
    border-radius: 0.25rem;
    background: #145a72;
    color: #ffffff;
    font-weight: 700;
    line-height: 1.2;
    text-decoration: none;
}

.read-more-button:hover,
.read-more-button:focus-visible {
    background: #0d3f50;
    color: #ffffff;
}

.read-more-button:focus-visible {
    outline: 3px solid #f4c542;
    outline-offset: 3px;
}

The contrast between the text and background should be checked with an accessibility tool, especially when using a brand palette. A visible focus state is important for keyboard navigation and should not be removed with outline: none. Australian businesses often need a site that works for users accessing it through public Wi-Fi, older laptops or mobile data, so a lightweight CSS treatment is preferable to a large image-based control.

If the link appears directly after an excerpt, display: inline-flex may place it beside the final line on wider screens. Add display: flex or a block wrapper if the design requires the control to sit on its own row. The choice should be tested with short and long summaries rather than judged from a single sample post.

Supporting Archives and Custom Templates

The excerpt_more filter applies when a theme uses WordPress’s automatic excerpt functions. It may have no visible effect if the theme prints custom content, calls the_content() instead, or builds archive cards through a page builder. In those cases, inspect the template and determine whether it uses get_the_excerpt(), the_excerpt() or a custom field.

A custom template can print the excerpt and link together:

<article <?php post_class( 'post-card' ); ?>>
    <h2 class="post-card__title">
        <a href="<?php echo esc_url( get_permalink() ); ?>">
            <?php echo esc_html( get_the_title() ); ?>
        </a>
    </h2>

    <div class="post-card__excerpt">
        <?php echo wp_kses_post( wpautop( get_the_excerpt() ) ); ?>
    </div>

    <a class="read-more-button"
       href="<?php echo esc_url( get_permalink() ); ?>"
       aria-label="<?php echo esc_attr( sprintf( 'Read more about %s', get_the_title() ) ); ?>">
        Read more
    </a>
</article>

This gives you more control over placement and avoids relying on the automatic suffix. The wp_kses_post() call allows safe post-style formatting in the excerpt, while the URL and label are escaped for their specific contexts. If a template already adds a read-more link, do not also use the filter, or visitors may see duplicate controls.

Block themes may render archive content through block markup rather than a PHP template. In that situation, use the Query Loop block’s post excerpt and read-more settings where available, or add a custom block pattern. PHP remains suitable for site-wide filters, but the visual placement may be controlled by the block editor.

Avoiding Theme and Plugin Conflicts

A common conflict occurs when a theme or plugin filters excerpt_more after your callback and replaces the returned HTML. The priority value controls execution order. The default priority is 10; using a later priority such as 20 or 99 can make your callback run after many existing callbacks, although it cannot guarantee control over every implementation.

Some plugins also strip HTML from excerpts or generate their own archive markup. SEO plugins, membership systems, multilingual tools and page builders may each alter how post summaries are produced. If the link disappears, temporarily disable suspected plugins in a staging environment and inspect the rendered source rather than relying only on the visual page.

For broader WordPress debugging guidance, a WordPress troubleshooting resource can help when hooks, template hierarchy rules or plugin interactions produce unexpected output. Keep custom code namespaced with a distinctive prefix to reduce collisions with theme and plugin functions, and avoid generic names such as custom_excerpt().

Caching can make a correct change appear ineffective. Clear the page cache, object cache, CDN cache and browser cache before testing. On an Australian hosting account, this may involve a control panel cache layer as well as a service such as Cloudflare. Check both logged-in and logged-out views because some cache systems serve different versions to administrators and public visitors.

Practical Checks Before Publishing

A polished read-more control depends on more than the PHP snippet. Check the complete archive experience, including keyboard navigation, translated labels, long titles and posts without featured images. The following checks cover the most common implementation problems:

Use meaningful link text when the same archive card contains multiple navigation controls. “Read more” is acceptable when the surrounding heading and accessible label identify the post, but a fully descriptive visible label may be better for some layouts. For example, “Read more about Sydney storm preparation” gives stronger context when links are listed in a screen-reader links menu.

The component should also handle translated sites and changing content. A translation plugin may need a translatable string instead of hard-coded English text, while a store that sells across Australia may need labels suited to products, services or resources. Keep the class name stable so visual changes can be made in the stylesheet without modifying PHP.

Testing the Final WordPress Implementation

Test the implementation on the home page, category archives, tag archives, search results and any custom post type archives. A theme may use different templates for each view, so the button can appear in one location while remaining absent elsewhere. Confirm that the excerpt itself is visible and that the link is not being hidden by overflow, fixed card heights or a conflicting display rule.

Accessibility testing should include keyboard-only navigation and a screen reader where possible. Focus must be easy to see, the link must be reachable in a logical order, and the accessible label should make sense when read without the surrounding card. Check the result with browser zoom at 200 percent and with text enlarged, as button padding and line wrapping can expose layout problems.

Finally, validate the change on the actual production stack after testing in staging. Australian users may be browsing from Brisbane, Adelaide or remote areas with slower mobile connections, so avoid adding unnecessary JavaScript for a simple navigation link. A semantic anchor, escaped PHP and focused CSS provide a reliable solution that remains maintainable as the WordPress site grows.