0
@media (max-width: 768px) {
  .page-id-9334 .site-content {
    display: flex;
    flex-direction: column-reverse;
  }
}

I am trying to load this CSS into Custom Taxonomy Pages...

My original question refers to a specific Page ID (and I edited my original question).

Anyways - based upon the replies below I thought that this would work but it throws an error, with or without the <style> CSS Opening Tags.

Can anyone else please shed some light on how I might be able to get this to work?

Thanks!

add_action( 'wp_head', function () {
    if ( is_tax(country) ) {

      <style>
      @media (max-width: 768px) {
        .site-content {
          display: flex;
          flex-direction: column-reverse;
        }
      }
      </style>

    }
} );
2
  • Are you saying that the code is added on every page and you just want it on page 9334? How you added that code - via a hook like wp_head?
    – Sally CJ
    Feb 3, 2021 at 9:32
  • Yes correct - it is added into wp_head so it loads throughout the site but of course should only work on Page ID 9334
    – Henry
    Feb 3, 2021 at 9:34

2 Answers 2

0

Seems there are a few elements missing

First is the quotes in is_tax(country), should be is_tax('country')

Second you are missing closing and opening PHP tags

When working with action that require html output you can do it in a few ways. For now we will stick with the method you wanted to use.

The final result would look like this

add_action( 'wp_head', function () {
  if ( is_tax('country') ) {
?>
  <style>
  @media (max-width: 768px) {
    .site-content {
      display: flex;
      flex-direction: column-reverse;
    }
  }
  </style>
<?php
  }
} );
1
  • thanks works great
    – Henry
    Feb 3, 2021 at 11:19
0

You said (via the comments) that you added the code via wp_head, so if you want the code be added only on the Page (post type page) with the ID of 9334, you can use is_page() which is one of the conditional tags in WordPress.

So for example:

add_action( 'wp_head', function () {
    if ( is_page( 9334 ) ) {
        // add your CSS here
    }
} );
2
  • Thanks for that but unfortuntely that threw an error. Also - my original question was wrong, I need this to load on Custom Taxonomy - sorry for the confusion
    – Henry
    Feb 3, 2021 at 10:16
  • Sorry for the simplified example, I thought you'd know that you need to close the PHP block of code before outputting a HTML, i.e. ?>HTML here<?php, without using string concatenation like echo 'this' . ' string ' . 'is <i>concatenated</i>';.
    – Sally CJ
    Feb 3, 2021 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.