# Widget Area Above the Footer

> Registers an "Above the Footer" widget area and shows its widgets in a responsive row just above the site footer, in classic and block themes.

- Type: PHP
- Runs: Run everywhere
- Category: [Widgets](https://wpide.com/library/category/widgets/)
- Tags: widgets, footer, layout
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/widget-area-above-footer/

## Code

```php
// Name and ID of the new widget area.
$wpide_prefooter_name = 'Above the Footer';
$wpide_prefooter_id   = 'wpide-above-footer';

add_action( 'widgets_init', function () use ( $wpide_prefooter_name, $wpide_prefooter_id ) {
    register_sidebar( array(
        'name'          => $wpide_prefooter_name,
        'id'            => $wpide_prefooter_id,
        'description'   => 'Shown on every page, just above the site footer.',
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget'  => '</div>',
        'before_title'  => '<h2 class="widget-title">',
        'after_title'   => '</h2>',
    ) );
} );

$wpide_prefooter_html = function () use ( $wpide_prefooter_id ) {
    if ( ! is_active_sidebar( $wpide_prefooter_id ) ) {
        return '';
    }

    ob_start();
    dynamic_sidebar( $wpide_prefooter_id );

    $style = '<style>.wpide-above-footer{display:grid;gap:1.5em;grid-template-columns:repeat(auto-fit,minmax(min(100%,240px),1fr));max-width:var(--wp--style--global--wide-size,1200px);margin:2em auto;padding:0 16px}</style>';

    return $style . '<aside class="wpide-above-footer" aria-label="' . esc_attr( 'Above the footer' ) . '">' . ob_get_clean() . '</aside>';
};

// Classic themes: printed when the theme loads footer.php.
add_action( 'get_footer', function () use ( $wpide_prefooter_html ) {
    if ( ! wp_is_block_theme() ) {
        echo $wpide_prefooter_html(); // phpcs:ignore WordPress.Security.EscapeOutput -- widget output.
    }
} );

// Block themes: added before the footer template part.
add_filter( 'render_block_core/template-part', function ( $content, $block ) use ( $wpide_prefooter_html ) {
    static $done = false;

    $slug = isset( $block['attrs']['slug'] ) ? (string) $block['attrs']['slug'] : '';
    $area = isset( $block['attrs']['area'] ) ? (string) $block['attrs']['area'] : '';

    if ( $done || is_admin() || ( 'footer' !== $area && 0 !== strpos( $slug, 'footer' ) ) ) {
        return $content;
    }

    $done = true;

    return $wpide_prefooter_html() . $content;
}, 10, 2 );
```

## Notes

Classic themes print it when they load footer.php; block themes get it before the footer template part.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Widget Area Above the Footer" 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/
