do_action( 'init' )

Fires after WordPress has finished loading but before any headers are sent.



EX 1

add_action('init', 'my_php_function');

function my_php_function() {

    if (stripos($_SERVER['REQUEST_URI'], 'page-with-custom-php') !== false) {

        // add desired php code here

    }

}
Insert PHP code In Wordpress Page and Post : stack overflow : https://stackoverflow.com/questions/18896146/insert-php-code-in-wordpress-page-and-post




EX 2

add_action('init', 'my_function');

function my_function() {

    if (!is_user_logged_in()) {

   ?>

      <style>

  .selector {}

      </style>

   <?php

    }

}




https://developer.wordpress.org/reference/hooks/init/

Posted by cpu21