• I can’t find any header.php file so how do we add any custom code inside head element in a child 2022 theme without using any plugin.

    • This topic was modified 2 years, 8 months ago by psychicsandra.
Viewing 5 replies - 1 through 5 (of 5 total)
  • You can use:

    /* Code in header */
    add_action('wp_head', 'code_header');
    function code_header(){
    ?>
    YOUR CODE HERE
    <?php
    };

    So, there is no header file in Twenty Twenty Two? I tried a plugin for this job but it’s flaky. It doesn’t always delete what it’s injected and i want to see exactly what i’m doing.

    May i ask please where ^that code would go?

    @joemcplumber
    You have to create a child theme from 2022. In that child theme copy the functions.php from the parent theme and then add the above code.

    Here is my functions.php code where I’ve added Google Analytics code. You can copy this entire content and paste in your functions.php in child theme.

    You can see it working on https://psychicdivinity.com/

    <?php
        add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles', 11 );
    
        function my_theme_enqueue_styles() {
            wp_enqueue_style( 'child-style', get_stylesheet_uri() );
        }
        add_action('wp_head', 'header_code');
    
        function header_code() {
            echo '<!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-NN2K5L"></script> <script>  window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag(\'js\', new Date()); gtag(\'config\', \'G-NN2K5L\');</script>';
        }
    
        add_filter( 'get_the_archive_title_prefix', '__return_false' );

    Damn WordPress, they disabled my other www.remarpro.com account for no reason. Can you stop suspending accounts?

    here< I am confuse, how do i create child theme of wordpress twenty twenty-two theme.

    i need to create child theme, add header.php, add functions.php and also be able to add footer.php. I need great tutorial on these. Everything just too confusing for me

    @thatmme There is no header or footer files in 2022 themes. You can create a folder then copy style.css and functions.php from parent theme and modify it as you need and then upload and activate. You can Google search on how to create a child theme.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to add custom code in header.php file’ is closed to new replies.