• Resolved anebi85

    (@anebi85)


    Hello,

    I am trying to add a custom header using a filter from my child theme but it looks like the filter is not applied at all and redirection plugin directly handles the redirect.

    The code I have is this:

    function add_header_xrobots( $headers ) {
        if( !( stristr( $_SERVER['REQUEST_URI'], '/ulos/' ) === false ) )
            $headers['X-Robots-Tag'] = 'noindex, nofollow';
    
            return $headers;
    }
    add_filter( 'wp_headers', 'add_header_xrobots', 10, 2 );
    

    May I ask you to tell me if there is an easy way to manipulate/add custom headers from inside the theme with a code?

    Thank you in advance!

    Kind regards,
    Ali Nebi

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter anebi85

    (@anebi85)

    I also tried with the send_header action but still doesn’t work.

    • This reply was modified 2 years, 2 months ago by anebi85.
    Plugin Author John Godley

    (@johnny5)

    This seems more of a general WordPress question than a Redirection one. It may be better moving it to another forum.

    You could try changing the priority of your filter, and making sure it is actually running.

    • This reply was modified 2 years, 2 months ago by John Godley.
    Thread Starter anebi85

    (@anebi85)

    Hello,

    Thank you for your reply.

    Well, that’s the interesting part. If I access an URL that is not processed by the Redirection plugin then the wp_header filter or sender_header action works, but when it is an URL handled by the plugin, my child theme filter/action is not ran at all.

    I tried to change the priority too but didn’t help. that’s why I decided to post my question here because I thought that you might know why the Redirection code is with higher priority than my code eventually.

    Best regads,
    Ali Nebi

    Plugin Author John Godley

    (@johnny5)

    The plugin uses send_headers in a standard way. I cannot say why your code isn’t working, but as above you should debug it and ensure that it is running, and is running at the right time.

    Thread Starter anebi85

    (@anebi85)

    Thank you very much, I keep checking and doing debugging.

    Best regards,
    Ali Nebi

    Thread Starter anebi85

    (@anebi85)

    Just a small update if someone else is going to deal with same situation. I was able to inject the header using the ‘init’ action. send_headers action and wp_headers filter is still not working but I will keep testing those when I have more time. In any case ‘init’ action with priority 9 or lower works fine.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom header from child theme’ is closed to new replies.