Hide Author Usernames in X-Child Theme

Hi,

I want to hide author usernames on my website. By that I mean when someone enters http://www.example.com/?author=1 into the browser, they are sent back to the homepage rather than presented with information regarding the author=1 (ie: admin author name).

Basically, I’m following Item #8 from this page…

I’ve tried adding the Item #8 sample code to the X-Child functions.php using link
https://www.example.com/wp-admin/theme-editor.php?file=functions.php&theme=x-child
but that doesn’t work.

What else can I try in order to hide general access to site user names?

Thanks!

Hi There @Gobaga

Thanks for writing in! Your referenced code has some character issues. Could you please try updating your code with the following and see if that helps.

add_action('template_redirect', 'bwp_template_redirect');
function bwp_template_redirect() {
  if (is_author()) {
    wp_redirect( home_url() ); exit;
  }
}

Hope that helps.

Thank you for the suggestion. I copied and pasted that code exactly into the page
https://www.example.com/wp-admin/theme-editor.php?file=functions.php&theme=x-child

I receive the following error when I attempt access to page:
https://www.example.com/?author=1

Parse error: syntax error, unexpected '}', expecting end of file in /<server wordpress path>/wp-includes/functions.php on line 6037

I’m not sure what to try next. The code you provided, and that I copied into the X-Child PHP editor, have no ‘loose’ curly brackets.

Here’s the entire X-Child Theme functions.php from the Theme Editor…

<?php

// =============================================================================
// FUNCTIONS.PHP
// -----------------------------------------------------------------------------
// Overwrite or add your own custom functions to X in this file.
// =============================================================================

// =============================================================================
// TABLE OF CONTENTS
// -----------------------------------------------------------------------------
//   01. Enqueue Parent Stylesheet
//   02. Additional Functions
// =============================================================================

// Enqueue Parent Stylesheet
// =============================================================================

add_filter( 'x_enqueue_parent_stylesheet', '__return_true' );



// Additional Functions
// =============================================================================
add_action('template_redirect', 'bwp_template_redirect');
function bwp_template_redirect() {
  if (is_author()) {
    wp_redirect( home_url() ); exit;
  }
}

Hi @Gobaga,

I could not see any problem of what you added. In this case, please share us your admin credentials so we could check your setup closer.

Don’t forget to set it in a secure note.

Thanks.

Also, I just noticed that I receive that error message only when accessing ?author=1 from Firefox. When using Safari or Chrome to access ?author=1, the browser is properly redirected to the home page.

Hello There,

You might be having a caching issue since you have Endurance Page cache in your site. Please purge all your site caches, clear your Firefox browser’s cache or use private browsing mode in Firefox and test it again.

Hope this helps. Kindly let us know.

Ah, yes! That worked! Thank you!

You’re more than welcome, glad we could help.

Cheers!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.