Support » Developing with WordPress » Add specific code in a specific page on WordPress

  • ivangfal2020

    (@ivangfal2020)


    Hi,

    I want to put a specific code, a google tag in the thank you page of the website, but I can’t find the way.

    I know I have to take the ID of the page, which is post=944, and modify the code in the theme editor with a function that says if post=944 add in the header this code.

    Can’t find a way to do it, I tried to put a function in function.php and in header.php, but haven’t worked out.

    I have the hello elementor theme.

    Could anyone help with that?

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

Viewing 1 replies (of 1 total)
  • Hello @ivangfal2020,

    First, I recommend using the Code Snippets plugin to add the code: https://wordpress.org/plugins/code-snippets/. If you add the Google Tag to your theme’s functions.php file and change your theme, the tag will also be removed. The Code Snippets plugin will also make it easier to manage tags like these, as you may need to use them on a different page or post later on.

    Please use the following code:

    /* Add Google Tag to Thank You Page (post=944) */
    add_action('wp_head', 'thankyou_tag');
    function thankyou_tag(){
    if(is_single( '944' )) {  ?>
    PASTE GOOGLE TAG CODE HERE
    <?php  }
    };

    It’s possible that your Thank You page is a custom post type, in which case you will need to use the following code (it uses is_singular rather than is_single):

    /* Add Google Tag to Thank You Page (post=944) */
    add_action('wp_head', 'thankyou_tag');
    function thankyou_tag(){
    if(is_singular( '944' )) {  ?>
    PASTE GOOGLE TAG CODE HERE
    <?php  }
    };
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.