Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #902876
    marihonaa
    Participant

    Hi!

    I have a code in place for adding header code to only one page (below)

    function scripts_to_head() {
    if ( is_page( 382 ) ) { ?>

    <!– Facebook Pixel Code –>
    Code cut out
    <!– End Facebook Pixel Code –>

    <?php }
    }

    add_action(‘wp_head’, ‘scripts_to_head’);

    This works well. Now I want to add different code to another specific page as well. I tried to add an elseif condition (I don’t really know PHP), but it gave me an error. Could you please help?

    Code I added below in bold.

    function scripts_to_head() {
    if ( is_page( 382 ) ) { ?>

    <!– Facebook Pixel Code –>
    Code cut out
    <!– End Facebook Pixel Code –>

    <?php }

    elseif ( is_page( 476 ) {

    Want to add different code here

    }

    }

    add_action(‘wp_head’, ‘scripts_to_head’);

    #903675
    Darshana
    Moderator

    Hi there,

    Thanks for writing in! Can you try the following sample code.

    
    function scripts_to_head() {
    	
    	if ( is_page( 382 ) ) { ?>
     		
     	  <!-- your script here -->
    
    <?php } else if ( is_page( 476 ) ) { ?>
    
    	  <!-- your script here -->
    <?php }
    
    }
    
    add_action('wp_head', 'scripts_to_head');
    
    #904860
    marihonaa
    Participant

    Works perfectly, thanks 😀

    #905370
    Darshana
    Moderator

    Glad we were able to help 🙂

  • <script> jQuery(function($){ $("#no-reply-902876 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>