• Resolved jgbranco

    (@jgbranco)


    I need to add a snippet to just a few pages or posts, how do I do that… Javascript snippets.

    Thanks.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Hi @jgbranco,

    You can do this by combining the is_page() and is_single() functions with the basic JavaScript snippet template:

    add_action( 'wp_head', function () {
    	if ( ! is_page( [ 142, 'about' ] ) && ! is_post( 'Hello World' ) ) {
    		return;
    	} ?>
    
    	<script>
    
    	/* js code goes here */
    
    	</script>
    
    <?php } );

    The above example will only add the JavaScript code to the page with the ID of 142, the page with the slug of ‘about’, and the post with the name ‘Hello World’.

Viewing 1 replies (of 1 total)
  • The topic ‘How do I add a Javascript Snippet to a particular page or pages a few pages’ is closed to new replies.