Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

PHP Does anyone knows how to sort this out?

Giscoding

Coder
Hi, I am having an issue with my site and it is driving me crazy for weeks now. My problem is simple yet I cannot find how to fix it.
The issue is:
In my Menu, all pages are set but when I click on the "Profile" page, it loads the "Home" page.
What I have tried so far:
-create a new menu and re-adding the pages
-redirection
-create a dummy profile page menu and replace it
-set it in the PHP functions
None of these made the "Profile" page show.
Yes, it is set to public.
The strangest thing is that when a new user registers, they land straight away on that "Profile" page, but then when moving to another page and going back to the same page will display the "Home" page.
 
Solution
In the menu code you provided, you have the menu hard-coded rather than pulling items from a menu under Appearance > Menus, which is why you don't see that link listed there. Looking at your code, it looks like your theme tries to get a unique profile page for each user based on a post ID set in the user meta. If you want everyone to just go to /my-profile instead you should be able to change:

PHP:
<li class="<?php global $current_user;

get_currentuserinfo();

if(is_singular('customers'))
    { echo 'current-menu-item'; };?>">
    
    <a href="<?php echo esc_url( get_permalink($cpostid) ); ?>">My Profile</a></li>   
    
<?php
}
else
{
?>

TO:

PHP:
<li class="<?php global $current_user;

get_currentuserinfo()...
What is your site? Are you using a Content Management System like Wordpress, or something you custom coded? What does the code that generates the menu look like? If you type the URL of the profile page in your browser directly do you see the proper page or do you get redirected to home?
 
Hi Mutiny,
Thank you for taking the time to answer.
My site is www.myimage.uk.com and done on WP with a Child Theme of my original custom theme.
The menu is HTML and saved in my PHP functions.
When a new user registers, she lands on www.myimage.uk.com/my-profile. Which is the correct page. But if she wants to navigate to another page and return to the Profile page, what display on the page is www.myimage.uk.com/home BUT WHAT SHOWS IN THE WEB browser is www.myimage.uk.com/customers/name and both are not the relevant pages.
 
Ok, registering on your site I see what you mean, the URL of the button appears to go to a ?user=username type URL. What do you have the button set to in your menu under Appearance > Menus in Wordpress? I'm assuming you have it set to /my-profile?

I think you might be seeing the homepage because of Wordpress' URL guessing feature. Here's some instructions to turn that off:

If you implement that, I suspect clicking "My Profile" while logged in will now send you to a 404 page.

If your menu is set to the correct path in the dashboard and the above link doesn't solve the issue, can you please post the code from your theme where you are calling / outputting that header menu?
 
I have added the code from Joseph Dickson, and when I check back the profile, I have now the WooCommerce user page instead. I am really not sure why because this page is not in my menu ( >Appearrance} AND is not in my HTML. If I disable WooCommerce, I land on the Home page again, and no error 404 page.
I will attach my menu HTML below
 

Attachments

  • Menu Html.rtf
    5.2 KB · Views: 1
In the menu code you provided, you have the menu hard-coded rather than pulling items from a menu under Appearance > Menus, which is why you don't see that link listed there. Looking at your code, it looks like your theme tries to get a unique profile page for each user based on a post ID set in the user meta. If you want everyone to just go to /my-profile instead you should be able to change:

PHP:
<li class="<?php global $current_user;

get_currentuserinfo();

if(is_singular('customers'))
    { echo 'current-menu-item'; };?>">
    
    <a href="<?php echo esc_url( get_permalink($cpostid) ); ?>">My Profile</a></li>   
    
<?php
}
else
{
?>

TO:

PHP:
<li class="<?php global $current_user;

get_currentuserinfo();

if(is_singular('customers'))
    { echo 'current-menu-item'; };?>">
    
    <a href="/my-profile">My Profile</a></li>   
    
<?php
}
else
{
?>

Specifically, the area that needs to change is:

PHP:
<a href="<?php echo esc_url( get_permalink($cpostid) ); ?>">My Profile</a></li>

TO:

PHP:
<a href="/my-profile">My Profile</a></li>

I've included both code blocks in case you need more context as to which section I recommend changing. Also, .rtf files are not good for sharing code, either use the editor here or upload to something like PasteBin that gives you some formatting as it was very hard to read as provided.
 
Solution
In the menu code you provided, you have the menu hard-coded rather than pulling items from a menu under Appearance > Menus, which is why you don't see that link listed there. Looking at your code, it looks like your theme tries to get a unique profile page for each user based on a post ID set in the user meta. If you want everyone to just go to /my-profile instead you should be able to change:

PHP:
<li class="<?php global $current_user;

get_currentuserinfo();

if(is_singular('customers'))
    { echo 'current-menu-item'; };?>">
   
    <a href="<?php echo esc_url( get_permalink($cpostid) ); ?>">My Profile</a></li>  
   
<?php
}
else
{
?>

TO:

PHP:
<li class="<?php global $current_user;

get_currentuserinfo();

if(is_singular('customers'))
    { echo 'current-menu-item'; };?>">
   
    <a href="/my-profile">My Profile</a></li>  
   
<?php
}
else
{
?>

Specifically, the area that needs to change is:

PHP:
<a href="<?php echo esc_url( get_permalink($cpostid) ); ?>">My Profile</a></li>

TO:

PHP:
<a href="/my-profile">My Profile</a></li>

I've included both code blocks in case you need more context as to which section I recommend changing. Also, .rtf files are not good for sharing code, either use the editor here or upload to something like PasteBin that gives you some formatting as it was very hard to read as provided.
Thank you for taking the time to do that, it's very kind of you. I am going to try it now and I will let you know how it went.
Just a question, by making these changes, will each user still be able to see this page as their own profile, or will it be a generic page that everyone can see?
 
The content of the page appears to pull information specific to the logged in user, so each user should see their own profile from what I can tell based on what I am seeing on your site.
 
The content of the page appears to pull information specific to the logged in user, so each user should see their own profile from what I can tell based on what I am seeing on your site.
Actually I am not so sure it worked. I have made the changes and it seemed ok, but when I tried to register as a new user ( to test) I got logged out and now cannot log back in WP admin, nor as a new customer. When trying to log in WP I get a redirection to login for customers but not the WP dashboard
 
The content of the page appears to pull information specific to the logged in user, so each user should see their own profile from what I can tell based on what I am seeing on your site.

The content of the page appears to pull information specific to the logged in user, so each user should see their own profile from what I can tell based on what I am seeing on your site.
All sorted,

Thanks again for your help
 

Latest posts

Buy us a coffee!

Back
Top Bottom