PHP hook to load first, before the page loads

I want to add a filter function that is called on page load in PHP. For example, I would like to check some argument before the page is loaded. It must be able to check some $_SESSION ['somearg'] variable.

  • Alex Stine

    Hello Gabi
    Hope you are well!

    I recommend using an action hook with a priority to make your code load early. Check the following code as an example.

    function some_example() {
    $some_variable = some_value();
    if($some_variable > 0) {
    // do something
    } else {
    // do something
    }
    }
    add_action('init', 'some_example', 1);

    I hope this helps. If you can provide more details on what you're looking to accomplish here, I can try to help with a more specific piece of code to meet your needs.

    Cheers,
    Alex :smiley:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.