How to get $tag to fill into add_action() or add_filter()?

These 2 function add_action() and add_filter() are magics of WP and do not directly affect your code. In WordPress, they use hooks for mocking into existing functions, methods without changing it’s code.

The $tag you are referring is the name of the hook that you want to use. List of core hooks can be found here https://codex.wordpress.org/Plugin_API/Hooks. However you can easily create for own hooks. E.g.:

  • When you create a theme, and you want to allow others to add some additional HTML after your header, you may create this snippet:

in functions.php (or in you lib)

function get_custom_header($tag){
    get_header($tag);
    do_action('after_template_header', $tag); // Add $tag as param, this $tag is not
}

in index.php (in theme) or in any theme file

<?php get_custom_header(); // instead of get_header(); ?>

For hooking, others need to add this: ($tag you are asking is ‘after_template_header’ for this case)

add_action('after_template_header', 'hook_to_header', 10, 1); // 4th param tell WP to use 1 arguments, if you put it 0, you will not need to pass $tag to function
function hook_to_header($tag) {
    echo "After header with tag '$tag' text here";
}

Hope this can help you learning WP well my fellow. Good understand on hooks will help you to do advanced development on WP.