Support » Plugin: Code Snippets » Exclude php snippet with script code from running on subpages

  • Michele

    (@mathrim87)


    Hi,
    I’m using this code to run my script only on specific pages based on IDs:

    add_action( 'wp_head', function () {
    	if ( ! is_page( [ 24738, 24739 ] )) {
    		return;
    	} ?>
    <script> my script </script>
    <?php } );

    But I realized that it would be better (in my case) to exclude all the subpages of a specific page. I’ll explain myself better.

    I want to exclude all these pages: http://www.my-site.com/course/name-of-the-course-1, http://www.my-site.com/course/name-of-the-course-2, etc

    In this way there is no need to “update” the snippet with all the new IDs of the pages that I want to exclude..

    Tips on how to do it would be really appreciated!

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