Add header code to each page except specific pages

Hello,
I have a code for a pop up form that I would like to use on all pages and posts except a few specific pages. I found some articles in the forum on how to add codes to the header of each page but can you help me with how to add a code to the header of each page and post but exclude specific pages for an X Pro site?

Thank you

Hi @smartermethods,
Thanks for reaching out.

You can add the specific code header by calling the wp_head action hook. I would suggest you add the following sample code into your child theme functions.php file.

add_action('wp_head', 'your_function_name');
function your_function_name()
{
    if(is_single(1234)) //specific page or post id
    {  
            //PASTE HEADER CODE HERE
    }
}

You can find more information on how to add the code in Header and Footer from this article: https://kinsta.com/knowledgebase/add-code-wordpress-header-footer/

Remember that the above code will work if copied as it is and don’t conflict with any existing code.
Please note that the code provided serves only as a guide to help you get started custom coding on your own if there’s no option offered in our theme or the products we bundle.
We do not provide support for custom codes that means we can’t fix it in case it conflicts with something in your site nor will we enhance it.
And if you are not proficient with the coding, I would suggest you hire a developer who can assist you to do the customization.

Thanks

1 Like

Thank you very much…

So just to clarify, if I DO NOT want the code to load in the header on pages 123, 241 and 344 then I would use the following code, correct?


add_action(‘wp_head’, ‘your_function_name’);
function your_function_name()
{
if(is_single(123, 241, 344)) //specific page or post id that I do not want the code to load on
{
//PASTE HEADER CODE HERE
}
}


Hi @smartermethods,

You can use the function as following :

is_single( array( 17, 19, 1, 11 ) ) // replace the ids with your page/post ids

You can find more details here: https://developer.wordpress.org/themes/basics/conditional-tags/#a-single-post-page.
And again I strongly suggest you hire a developer who can assist you to do the customization. As we do not provide support for custom codes that means we can’t fix it in case it conflicts with something in your site nor will we enhance it.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.