• nootkan

    (@nootkan)


    I found this code while browsing the forum and implemented it inside my child-theme>>functions.php file and it seems to work.

    add_action('template_redirect', 'my_custom_disable_author_page');
    
    function my_custom_disable_author_page() {
    	global $wp_query;
    
    	if ( is_author() ) {
    		$wp_query->set_404();
    		status_header(404);
    		// Redirect to homepage
    		// wp_redirect(get_option('home'));
    	}
    }

    However, I keep seeing this warning in my error logs:

    PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘remove_author_pages_page’ not found or invalid function name in /home/mywebsite/public_html/wp-includes/class-wp-hook.php on line 288

    Can anyone shed some light on what I may have done wrong?
    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • munyagu

    (@munyagu)

    Hi,

    Remove
    add_action( 'template_redirect', 'remove_author_pages_page' );.

    It’s exists another line in function.php.

    Didn’t you copy and paste this code together?

    Thread Starter nootkan

    (@nootkan)

    Thanks for your reply. I did copy and paste the code and the extra add_action was there. I just omitted it when posting here for some reason.

    In any case your solution did the trick. It now redirects to 404 without the warnings.

    Thanks again for your support.

    Thread Starter nootkan

    (@nootkan)

    One more question if you don’t mind?

    I would like to now have it redirect to the home page instead of 404 page.

    The example states that I just have to comment out the two lines for the 404 redirect and uncomment the wp_redirect which I did.

    It still redirects to a 404 page and I was wondering if there is another way to achieve what I want?

    Thanks again for your support.

    function my_custom_disable_author_page() {
    	global $wp_query;
    
    	if ( is_author() ) {
    		// $wp_query->set_404();
    		// status_header(404);
    		// Redirect to homepage
    		wp_redirect(get_option('home'));
    	}
    }
    
    add_action('template_redirect', 'my_custom_disable_author_page');

    @nootkan

    You must exit after wp_redirect.

    wp_redirect(get_option('home'));
    exit();
    • This reply was modified 4 years, 12 months ago by munyagu.
    Thread Starter nootkan

    (@nootkan)

    Once again thank you for replying it is greatly appreciated.

    I did try using exit; as per this link: function wp_redirect

    Even with the parenthesis added as per your solution, it still isn’t working.

    It seems no matter what I try I get sent to a 404 page every time.

    I’ve cleared cache, tried several browsers to confirm it wasn’t a cache issue and tried various code changes based on google searching.

    I’ve de-activated/re-activated all plugins one at a time and used ctrl F5 to clear cache but that didn’t show any conflicts with plugins. Did the same for the theme.

    One thing I noticed is when I remove the snippet entirely from the child theme>>fuctions.php file the 404 issue still exists.

    So now I assume there must be another issue and the snippet works.

    I will keep trying but I may have to settle for the 404 error page (hopefully not).

    Any other ideas that may lead me to a solution?

    Thanks again for your support!

    • This reply was modified 4 years, 12 months ago by nootkan. Reason: added more content
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Problem with php code to remove author page’ is closed to new replies.