Example 1 — Show a message on attachment pages
Check the page type and print a short note.
<?php
if ( is_attachment() ) {
echo '<p>You are viewing a media file.</p>';
} How It Works
is_attachment()istrueon an attachment page.- The message is printed only there.
- On normal posts nothing is printed.

