skip to Main Content

Not sure if this is only problem for Elementor full width template, but it seems to override theme header.php. I tried achieving my goal by using elementor custom code feature, but it adds my code somewhere in middle of the tag.

What is the propper way of adding my own custom code as the first thing that is after the element?

3

Answers


  1. You are right Elementor overrides the theme’s header.php file so importing your code to this file is not effective. You need to add custom function to earn your goal. With the wp-head action you could add the code right into your header and Elementor will not override it.

    Add this code to the functions.php file od your active theme.

    add_action('wp_head', 'custom_head_function');
    function custom_head_function(){
    ?>
    YOUR HEADER CODE HERE
    <?php
    };
    

    UPDATE – If you want to set your code at the top

    As sephsekla mentioned in comment, there is a way to set the priority into your action to get it to the top. Try to set value to -999. So, choose a very low number and if there is no other lower number in your plugin or theme you will go straight to the top.

    add_action('wp_head', 'custom_head_function', -999);
    function custom_head_function(){
    ?>
    YOUR HEADER CODE HERE
    <?php
    };
    
    Login or Signup to reply.
  2. Elementor now supports custom code (javascript, html, etc) and supports the specific use of elements in the head of the page.

    Login or Signup to reply.
  3. What you are looking for you can find at the WordPress Dashboard> Elementor > Custom Code . Then you will be able to add a custom code to the head: https://elementor.com/help/custom-code-pro/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search