Issue with @media print and hiding elements

I've been racking my brain for hours trying to figure out why this isn't working. I have a Wordpress site where I'm attempting to hide the header, menu, and footer content from being printed. Within my theme's style.css file, there is a section located at the bottom known as @media print that contains all the print-specific styles. I attempted to include the following within this section:

#search-box-wrap,
#search-box,
#inner-header,
#site-heading,
#site-generator,
#header,
#menu,
#sidebar,
#footer {
    display:none !important;
}

All of these ids correspond to the header/menu/footer div ids in my Wordpress site.

The stylesheet link is as follows:

<link rel="stylesheet" type="text/css" href="<?php bloginfo( 'stylesheet_url' ); ?>" />

Many sources online suggested removing the media parameter from the stylesheet link above (which I have done) because when you integrate the print styles with your regular stylesheet, you cannot simply use the media="screen" attribute...which makes sense, but I still can't understand why it's not working?

Despite adding the code to my style.css file, when I view Print Preview or use my Web Developer Toolbar to inspect Print-Only CSS Styles, the header/menu/footer sections are still visible. Can anyone assist me in understanding why this issue persists?

Answer №1

For those looking to apply these styles for printing purposes, it is recommended to include media="print" in the code snippet below:

<link rel="stylesheet" type="text/css" href="<?php bloginfo( 'stylesheet_url' ); ?>" media="print" />

To learn more about different media types, you can visit this link

Print

This particular style is intended for printed materials or documents viewed on screen in print preview mode. It's advisable to refer to the section on paged media for details regarding formatting specific to paged media.

UPDATE: Following a discussion with OP, the following solution proved effective:

  • Attempt linking directly without reliance on PHP codes

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for modifying the font style of a Bootstrap form input using a custom font

While developing my website using Bootstrap 4, I encountered an issue with the custom font (GeosansLight) I applied to the entire website through the body's CSS attribute. The problem arose when the default Bootstrap form inputs appeared too light to ...

Updating the background image for a radio button

Is it possible to customize the background image within the active radio button from the default redmond to aristo? .ui-radiobutton-icon { background-image: url("/images/ui-icons_38667f_256x240.png.jsf"); } Can someone help with the correct syntax for t ...

How to position Angular Component at the bottom of the page

I have been working on my angular application and recently created a footer component that I want to stay at the bottom of the page like a typical footer. The footer component is included in the default app.component.html file, which makes it visible on th ...

Is there a CSS Blend Mode alternative for Internet Explorer?

I've implemented the background-blend-mode on this element: <a href="#" class="blend"> <h3>Title</h3> <p>Content goes here</p> </a> It's all set up with a background-image url. When the element with c ...

Other options to consider besides using flex wrapping

Is it possible to use other methods to wrap these image items with the display: flex; property besides using the flex-wrap property? Are there alternative approaches available? body { margin: 0px; } img {} h1 {} p {} a { background-color: #ddd; ...

What are the best ways to create image animations on top of other images using CSS or JavaScript?

Imagine if the first image is in black and white, while the second one is colored. How can we make the black and white image change to color after a timeout period, with an animation similar to loading progress bars? Is this achievable using CSS or JavaScr ...

What is the best way to align the main text to the far left in a Bootstrap 4 cover template?

I am struggling to align the text to the far left of the page instead of it being centered. "Cover your page. Cover is a one-page template for creating elegant and uncomplicated home pages. Customize it by downloading, modifying the text, and inserti ...

How to keep a centered div in a lengthy box using Bootstrap

After successfully creating a simple web page with a header containing both an image and text, followed by three blocks of content below it, the final addition I need to make is another block of text beneath the existing three. This new block should be cen ...

Inconsistent performance: Twitter Bootstrap navigation functions flawlessly on desktop but encounters issues on

I have been using the collapsing navigation menu from Twitter Bootstrap for my website as shown in this demo: While it works perfectly fine on desktop browsers when I resize the window, it doesn't seem to work on my mobile device (iPhone 4s). The Bo ...

Is there a way to customize the hover color of the Bootstrap 4 navbar toggler?

I'm working with Bootstrap 4 and I would like the color of my navbar toggle icon (commonly referred to as the burger menu) to change when it is hovered over. I have attempted the following code but it is not producing the desired result: .navbar-light ...

My CSS horizontal drop-down menu is causing the sub-navigation items to overlap each other

I'm having an issue where my sub navigation menu items are stacking on top of each other instead of displaying properly. Here is the code snippet causing the problem: /* STYLING FOR NAVIGATION MENU */ .nav-bar { width: 100%; height: 80px; ...

Problem with personalized Domino login page

I have been working on creating a custom login page in domcfg.nsf. Everything is functioning as expected, except for the Style Sheets. I am attempting to load them from the same Domino server, but it appears they are unable to load until I actually log in ...

Is there a difference in font size between Firefox and Webkit browsers?

The issue with different fonts (Myriad Pro) displaying in Firefox and Webkit browsers (such as Chrome and Safari) has been noticed. Testing on Internet Explorer has not yet been conducted. form.standard.small input[type=submit] { width: 104px; h ...

Effortlessly alternate between dual-column and single-column layouts using CSS

Creating a basic two column layout with fixed widths is my current project. <div id='box'> <div id='ontop'>Ontop</div> <div id='column1'>Column1</div> <div id='column2'&g ...

What is the best way to incorporate both images and text in PHP code?

I'm currently working on creating a large image call-to-action (CTA) for my new WordPress website. I've set up a new field group with the type "group" in ACF, and added some functions in PHPStorm. However, none of my images, text, or links are ap ...

CSS: Placing items within an ng-for loop utilizing the "fixed" position property

<ul class="nav nav-pills nav-stacked" style="list-style: none"> <li *ngFor="#el of dragZoneElems; #idx = index"> <h4 style="position: fixed; top:'idx'*10" [dragResponder]="el">{{el.first}} {{el.last}}</h4& ...

Enhancing image clips using jQuery techniques

Could someone help me figure out why the image clip value isn't changing when I move the range slider in the code below? $('#myRange').on('input', function() { var nn = $(this).val(); $("img").css({ 'clip': ...

The box inside a MUI TextField input is consistently visible

My form utilizes MUI Form within a Dialog, but I am facing an issue where the TextField always displays with the border of a filled variant instead of the standard look. Additionally, when trying to integrate an Input from the NextUi library, I encountered ...

Display or conceal a div based on the size of the screen using HTML and CSS

Hey there, I recently finished my first React Project and I’m wondering if there’s a way to hide the 'side-menu' section on mobile screens using CSS. Any suggestions? <div className='side-menu'> <SiderComponent /> < ...

"Discover the versatility of implementing a single ag grid across various components, all while dynamically adjusting its style

I am facing an issue where I have an angular grid ag-grid in component1, which is being used in some other component2. Now, I need to use the same component1 in component3 but with a different class for ag-grid, specifically 'ag-grid-theme-dark'. ...