Theme & Front End CSS Beginner

Clean Print Styles for Posts

Hide headers, menus and sidebars when a page is printed, and show link addresses after link text.

Tested on WordPress 7.1 No plugin needed Updated
style.css 33 lines
@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;
	}
}

Where to add this

Recommended Additional CSS Appearance → Customize → Additional CSS, or your page builder's global CSS.
Child theme At the end of your child theme's style.css file.
A code snippets plugin As a CSS snippet set to load on the front end.

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.

How it works

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.

Things to watch

  • Some themes use their own element names. Add your theme’s header or sidebar class if it still prints.
  • Background colours and images are left out by most browsers when printing unless the visitor turns them on.

How to test it

Open a post and press Ctrl+P (Cmd+P on a Mac). The preview should show only the article, with link addresses after links.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only