Hello, I am using the WPDiscuz plugin.
I want to modify the URL of “Please LOGIN to comment”.
I have added this code in the functions.php file of my WordPress theme (Magnitude) but it doesn’t work, I am always redirected to wp-login.php.
add_filter (‘login_url’, ‘my_login_linkchanger’);
function my_login_linkchanger ($ link) {
/ * what to do with the link * /
return home_url (‘/ login’);
}
I need your help because it is very important to change the URL for me.
Thanks and regards.
Hi @guillermorivr,
First you should have a login page. Do you have a login page other than the default WordPress wp-login.php? If you don't have any other login page then you don't have any URL to change.
In case if you have one, and the URL of that page is example.com/my-login-page/ , the inserted code should look like this:
add_filter ('login_url', 'my_login_linkchanger');
function my_login_linkchanger ($link) {
return home_url ('/my-login-page/');
}
I have inserted the code at the end of the functions.php file (I see this file appears in wp-includes and in my theme directory). I modify the file that is inside the directory of my theme.
After doing this, now when I go to view the content of an article, an error appears.
Have I misplaced the code or what is happening?
Attached images.
I updated the code, please change it. The wrong part was copied from your post. So that too.
Please remove the code provided above and use the following one and you'll be redirected to the same post page.
add_filter ('login_url', 'my_login_linkchanger');
function my_login_linkchanger ($link) {
global $post;
$redirect_to = '';
if (!empty($post->ID)) {
$redirect_to = '?redirect_to=' . get_permalink($post->ID);
}
return home_url ('/my-login-page/' . $redirect_to);
}
Save, delete all caches, and check again.