0

I have 2 extra pieces of code in wp-blog-header.php.

The first handles 410 and 404 headers and goes at the top, before the line if ( !isset($wp_did_header) ) {

The second handles some complex redirects and goes after the wp(); line.

I know it's a bad idea to hack core WP scripts (especially as my hacks get overwritten on most WP updates). I'd like to do both as plugins, but I can't figure out which hooks to use, nor how.

I've looked at a few existing plugins, but none do what I need.

Any advice would be appreciated.

  • You’re going to need to be specific about what you’re trying to do. – Jacob Peattie Jun 23 '18 at 2:00
  • Thanks. Let's settle the first section of code first. It looks for unwanted things in the request's query string (the results of unsuccessful experiments like "modpagespeed" and "wp_touch"). It also looks for deleted articles using an array and returns a 410 header so the search engines no longer cache them. The plugin 410 for WP almost does what I want here, but doesn't. The only place I could get my code to work was before the if ( !isset($wp_did_header) ) { line. – MBourne Jun 23 '18 at 4:24
  • Can someone please help steer me in the right direction with this? – MBourne Jun 25 '18 at 7:01
  • For anyone else who needs it, I solved it as follows via a plugin: (1) The first block of code needed to be triggered with: add_action( 'wp_loaded', 'redirect_block' ); (2) The second block involving redirects was originally after the wp(); call, so in the plugin it is triggered as follows: add_action( 'wp', 'redirect_old_style_urls' ); – MBourne Jun 27 '18 at 7:00
  • If you have a solution, post it as an answer. – Jacob Peattie Jun 27 '18 at 7:01
0

For anyone else who needs it, I solved it as follows via a plugin:

(1) The first block of code needed to be triggered with: add_action( 'wp_loaded', 'redirect_block' );

(2) The second block involving redirects was originally after the wp(); call in wp-blog-header.php, so in the plugin it is triggered as follows: add_action( 'wp', 'redirect_old_style_urls' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.