There is a block on the site that I want to always appear with the exception of a few pages, i.e. need to hide it on certain pages. I try to write such a construction in the functions.php file, if you insert html tags, then they work, but if the styles are not, then how can this be solved without scripts and plug-ins?

<span class="conversion">блок, который нужно скрыть</span> if ((!is_page('44')) || (!is_page('57'))) { ?> <style type="text/css"> .conversion { display:none; } </style> <?php } ?> 
  • Why in the functions.php file, not single.php? - alenkins
  • @alenkins because for single.php even html tags do not work out .. - Vasya

1 answer 1

I do not quite understand why you are doing something in functions.php.

In my opinion, the right way is to make a special template for displaying the indicated pages. This can be done in two ways:

  1. If there is one unique page, copy the page.php file to page.php page-{id}.php in the theme directory, where you substitute the page ID for {id} .
  2. The most successful option. Copy page.php with any convenient name that will be clear for you to identify a new template (for example template-contacts.php ). Inside this file, insert this comment: <?php /* Template Name: Страница контактов */ ?> (Of course, instead of the phrase "contact page" you can write something of your own). After that, in the content editor of the page you can select this template for any page you need.

After that, change the layout of the new template as you need.

Material on this topic:

  1. Creating your own page templates
  2. 3 ways to create a page template

Updated

If you want to hide some kind of block with styles, you can take into account that most of the themes usually add a page-id-{id} class to the body tag. Thus, you can add the following rule to the end of the style file:

 .page-id-44 .conversion, .page-id-57 .conversion { display: none; } 

Ps. Do not touch functions.php unnecessarily. As such, the layout should not be there.

  • the gag is that the block (conditional banner) is not taken from the page.php page page.php . Is there really no option to hide the block easier? - it is simply incomprehensible to me why suddenly the standard style tag does not work out or it is overlapped by the style.css file - Vasya
  • one
    Specifying the question is better to add to the text of the question. As for where the block comes from, you didn’t write anything and, until you do this, you can hardly figure out how to solve your problem - tutankhamun
  • found a solution! I did not immediately notice that a style is being created, but with a rank lower in importance than that of style.css , which is not very obvious, since The style tag in the index file is always higher. added inportant - earned! - Vasya