最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

css - Trying to hide a button on a specific WordPress Page ID

programmeradmin6浏览0评论

I am trying to hide this button:

<button onclick="window.location.href='/';">About Me</button>

The entire HTML (for that specific section) is (including the title):

<aside id="secondary" class="widget-area">
        <div class="about-wrapper">
        <h2 class="widget-title">About Me</h2>
                <p class="about-copy"> text </p>
        </div>
</aside>

The Page ID is 52, I checked in the code and saw this:

<body class="page-template-default page page-id-52 no-sidebar">

The issue is that there isn't a CSS class....maybe I should add one - or - is there another way to hide this JavaScript button per Page ID in WordPress?

I am trying to hide this button:

<button onclick="window.location.href='https://example/about/';">About Me</button>

The entire HTML (for that specific section) is (including the title):

<aside id="secondary" class="widget-area">
        <div class="about-wrapper">
        <h2 class="widget-title">About Me</h2>
                <p class="about-copy"> text </p>
        </div>
</aside>

The Page ID is 52, I checked in the code and saw this:

<body class="page-template-default page page-id-52 no-sidebar">

The issue is that there isn't a CSS class....maybe I should add one - or - is there another way to hide this JavaScript button per Page ID in WordPress?

Share Improve this question edited Apr 11, 2020 at 12:44 Henry asked Apr 11, 2020 at 12:19 HenryHenry 9831 gold badge8 silver badges31 bronze badges 5
  • Did you check if page-id-52 class is actually present? – Himad Commented Apr 11, 2020 at 12:20
  • Hi @Himad yes I did and have updated question – Henry Commented Apr 11, 2020 at 12:24
  • If you use Chrome, can you check with the developer tools if the CSS is being applied? – Himad Commented Apr 11, 2020 at 12:28
  • Perhaps your rule does work, but there's a more specific rule that says otherwise? Is this just a CSS question? If so you might get more eyes on this if you asked on stackoverflow – Tom J Nowell Commented Apr 11, 2020 at 12:43
  • Sorry @Himad my question was worded all wrong. The issue is the button not the title. – Henry Commented Apr 11, 2020 at 12:45
Add a comment  | 

1 Answer 1

Reset to default 1

so if you want to remove/hide only the button can do this: 1 - if you have a specific class that hide a element //$class = "youre class";

 <button class="<?php if(is_page($page_id)){ echo $class } ?>" 
 onclick="window.location.href='https://example/about/';">About Me</button>

2 - inline style

 <button  <?php if(is_page($page_id)){ echo "style="display: none"; } ?>" 
 onclick="window.location.href='https://example/about/';">About Me</button>
发布评论

评论列表(0)

  1. 暂无评论