Hide headers, menus and sidebars when a page is printed, and show link addresses after link text.
@media print {
header,
footer,
nav,
aside,
.comments-area,
.wp-block-buttons,
#wpadminbar {
display: none !important;
}
body {
background: #fff;
color: #000;
font-size: 12pt;
}
a[href^="http"]::after {
content: " (" attr(href) ")";
font-size: 0.85em;
word-break: break-all;
}
img {
max-width: 100% !important;
break-inside: avoid;
}
h2,
h3 {
break-after: avoid;
}
}
Recipes, guides and documentation get printed, or saved as PDF, more than you’d think. Without print styles, the printout includes menus, sidebars and footers. This CSS gives a clean, readable page.
Rules inside @media print only apply when printing or saving as PDF. The snippet hides site chrome such as the header, menus, sidebars, comments, buttons and the admin bar, and switches to black text on white at a print-friendly size.
Because links can’t be clicked on paper, each external link is followed by its address in brackets. Headings are kept with the text that follows them, and images aren’t split across pages.
Open a post and press Ctrl+P (Cmd+P on a Mac). The preview should show only the article, with link addresses after links.