I got critical error after adding the code to functions.php

Dear Sirs,

For security reasons, may I clarify with you if I can add the code to the functions.php file in order to protect the custom wordpress login page? If so, why did I get the error message? What is going wrong? Should I just replace the custom login file name, right?

add_filter( ‘login_url’, ‘custom_login_url’, PHP_INT_MAX );
function custom_login_url( $login_url ) {
$login_url = site_url( ‘access.php’, ‘login’ );
return $login_url;
}

image

Read this

7 Likes

Sure, you can do that. There are plenty of security plugins that can do this, but you’re free to create your own if you want.

I’m assuming you’re referring to the functions.php file of your custom plugin, right? Not a WordPress core file? Because hacking the WordPress core code is not a good idea, because it will be wiped if you upgrade.

As for why the code crashes, please make sure your code is valid. I’m not sure what you actually put in your site, but the code you shared uses to quote strings, but that curved quote is not a valid code character. You can use single quotes (') or double quotes ("), but not the character you used.

But please learn how to debug your WordPress code yourself. Writing some code, deploying it, see if it works, and then asking us to fix it if it doesn’t is not the way to create a plugin. You should be able to troubleshoot issues on your own first.

5 Likes

Hi KangJL,

Thank you for your information. However, It’s not related my issue.

Hi Admin,

I know some security plugins can do that, such as WPS Hide Login. Due to having a lot of plugins, I want to use codes instead.

The functions.php file is in wp-includes because I didn’t find it in wp-contents>themes.

I will try to use single quotes (') or double quotes (") as mentioned and then report to you later on.

Thank you

Take note it will get over-written with every WordPress update. Not advisable
as it is not best practice in the first place. You cannot find it because it is in your theme folder.

What is the url? What is the theme you are using?

5 Likes

I would think the best way to package your extra functionality is as a plugin. Plugins are the way you can extend WordPress functionality without having to modify the WordPress core code.

I get that you want to reduce the number of plugins, but if you’re making a very simple plugin yourself, the overhead of the plugin system itself should be negligible.

4 Likes

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

Dear KangJL and Admin,

After adjusting the code as per Admin’s suggestion, I can successfully change the Custom Login URL.

KangJL, I used the WordPress Theme is called “TwentyTwentyThree” which didn’t provide functions.php file in wp-contents>theme. That’s why I used the function.php file in wp-include. Moreover, I tried to add the code to another theme that has functions.php file in wp-contents>theme. Both websites didn’t show error messages.

I really appreciate you spending your valuable time and providing your professional advice on my issue.

Thank you so much for your assistance.

functions.php are usually used for creating child themes in this context

6 Likes

Hi KangJL,

Thank you for providing information.

I will read this article to learn more.

Regards & Thanks

1 Like