Home > other >  Hook not trigger
Hook not trigger

Time:01-03

I am new to wordpress and I can not find a way to make any hook work. I use a child theme with this function.php

<?php
function custom_callback_function(){
    // add your custom code here to do something
    echo 'I will be fired on WordPress initialization';
}
add_action( 'init', 'custom_callback_function' );
?>

I tried different hook, placing the add_action above the function name. Does not matter, does not work.

Thank you for any help/

CodePudding user response:

When you write functions, you can assign them a priority, which tells WordPress when to run them.

By default, WordPress assigns a priority of 10 to functions which haven't had a priority added, if you want to fire your function after it, you use a number larger than 10.

A function in your parent theme may have a priority assigned to it. So you want to make sure the priority you give the function in your child theme is higher.

function custom_callback_function(){
    // add your custom code here to do something
    echo 'I will be fired on WordPress initialization';
}
add_action( 'init', 'custom_callback_function', 20 );

CodePudding user response:

Try an exit; after the echo. Maybe html/css covers the output. I tried it locally and the hook works.

  • Related