0

Goodevening,

i create a CPT (newsletter) and i want to hide from specific pages. I try to do that with many ways, but the newsletter not hide.

Edit: I want to hide in page subscribe {slug} and 6677 {id}

1) JQuery

    jQuery(document).ready(function($) {
      if (window.location.pathname == "localhost/mysite/subscribe/") {
             $('.subscribe').hide();
      } 
 });

2) Conditional tags

<?php if(is_page(6677) ) { ?>
<style>
  .subscribe-content{
      display: none!important;
  }
</style>
<?php } ?>

3) parameters in CPT array

<?php 
    $args = array(
    'post_type' => 'subscribe',
    'post_status' => 'publish',
    'posts_per_page' => -1,
      'post__not_in' => array(6677,613),
    'caller_get_posts'=> 1
    );  

  $the_query = new WP_Query( $args );
  if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

<?php the_content();?>

     <?php endwhile; else : ?>
        <center><h2> Do nothing</h2></center>
        <?php endif; ?>
      <?php wp_reset_postdata(); ?> 

Thanks in advanced.

0

I assume your page name is subscribe
for Jquery code you have to specifiy pathname not whole wp url ;

jQuery(document).ready(function($) {
if (window.location.pathname == "/theme/subscribe/") {
 document.getElementsByClassName("subscribe").style.display="none";
      } 
 });

in php code here is same example using page name or slug ;

<?php if(!is_page('subscribe') ) { ?>
 <style>.subscribe-content{display: none!important;}</style> 
    <?php } ?>

You can use arry to add more than one page if(!is_page(array(6677,613) )

3
  • yes my page is subcribe (i make the edits in my first post). In your first solution i try to understand the pathename, for the second solution, don't work. Also i add <?php if(!is_page('subscribe') ) { ?> to hide in the pages and works, but for specific page not work.
    – user24259
    Feb 16 '16 at 0:49
  • OK how you included your CPT to other pages ! for Jquery code full path should look like this http://yoursite.com/subscribe/ so JS page path should be /subscribe/.. and yes if you want hide it from subscribe a not ! Code should work .
    – Salem F
    Feb 16 '16 at 0:57
  • The CPT included in the footer of website, but with some css i add as "z-index" in all the website. For Jquery : the path is http://localhost/theme/subscribe/ the problem still remaining.
    – user24259
    Feb 16 '16 at 1:06
0

Form begin i wanted to hide from some pages, like the 'subscribe-page', 'contact form' the project is an eCommerce (Woocommerce).I try with the solutions above, but the problem remained. The only solution and less time-consuming :

<?php get_template_part('parts/subscribe', 'content');?>

And i add for every page/category that i want.

Even if the problem solved, i really want to know why the Conditional tags do not work.

Thanks in advanced.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy