Skip to content

Snippet: Change the Attachment Page Layout

The following snippet can be used to alter your attachment.php page layout. This is the page that is used to display attachments (images, videos, pdfs, etc) on the front-end. By default the attachment page uses the same layout as your standard pages which you can alter via the Customizer.

/**
 * Filters the post layout class.
 *
 * @link https://totalwptheme.com/docs/snippets/change-attachment-page-layout/
 * @param string $class (options full-screen, full-width, left-sidebar, right-sidebar)
 */
add_filter( 'wpex_post_layout_class', function( $class ) {
    if ( is_attachment() ) {
        $class = 'right-sidebar';
    }
    return $class;
}, 20 );
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top