Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

How to exclude page from hook

  • Hi all,
    I am using code snippet to “inject” this code:

    
    <?php
    add_action('wp_body_open', function() {
    	?>
    	<div class="smooth-wrapper">
    		<div class="smooth-content">
    	<?php
    });
    add_action('generate_after_footer', function() {
    	?>
    	</div>
    	</div>	
    	<?php
    

    I would like to exclude the frontpage.
    What is the best way to go about it?

    I tried using a hook element but somehow I failed.

    Thanks in advance

  • Hi there,

    You can wrap your HTML output using an if condition.
    And for not ! front_page you can use this : ! is_front_page()

    
    add_action('wp_body_open', function() {
      if ( ! is_front_page() ) {
        ?>
        <div class="smooth-wrapper">
        <div class="smooth-content">
        <?php
      }
    });
    add_action('generate_after_footer', function() {
      if ( ! is_front_page() ) {
        ?>
        </div>
        </div>	
        <?php
      }
    });
    
  • Excellent, David.
    Thanks very much.

  • You’re welcome

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.