{"id":122,"date":"2025-02-06T12:40:03","date_gmt":"2025-02-06T12:40:03","guid":{"rendered":"https:\/\/documentation.userswp.io\/article\/how-to-hide-user-profile-from-other-users\/"},"modified":"2025-03-27T16:39:39","modified_gmt":"2025-03-27T16:39:39","slug":"how-to-hide-user-profile-from-other-users","status":"publish","type":"gd_place","link":"https:\/\/userswp.io\/documentation\/article\/code-snippets\/how-to-hide-user-profile-from-other-users\/","title":{"rendered":"How to Hide User Profile from Other Users?"},"content":{"rendered":"\n<p>You can use the following code snippet to hide user profile from other users.&nbsp;<\/p>\n\n\n\n<p>In other words, when implemented, the given code snippet will ensure that only the currently logged-in user can see their profile, and nobody else. As such, viewing &#8220;others&#8217; profiles&#8221; will no longer be possible.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Hiding User Profile from Other Users<\/h2>\n\n\n\n<div class=\"wp-block-blockstrap-blockstrap-widget-alert d-flex align-items-center fade show alert alert-info mb-3\" role=\"alert\"><span class=\"fas fa-info-circle me-2\"><\/span><span class=\"flex-grow-1\">We recommend using the <a href=\"https:\/\/wpgeodirectory.com\/documentation\/article\/useful-plugins\/code-snippets-plugin\/\" target=\"_blank\">Code Snippets<\/a> plugin to add snippets to your site.<\/span><\/div>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\">add_action(&#039;template_redirect&#039;, &#039;template_redirect_cb&#039;, 9);\n\nfunction template_redirect_cb(){\n\tglobal $post;\n\tif ( ! is_page() ) {\n\t\treturn false;\n\t}\n\tif ( uwp_is_page_builder() ) {\n\t\treturn false; \n\t}\n\t$current_page_id = isset($post-&gt;ID) ? absint($post-&gt;ID) : &#039;&#039;;\n\t$uwp_page = uwp_get_page_id(&#039;profile_page&#039;, false);\n\tif ( $uwp_page &amp;&amp; ((int) $uwp_page ==  $current_page_id ) ) {\n\t\t$user = uwp_get_user_by_author_slug();\n\t\tif ( !(is_user_logged_in() &amp;&amp; $user &amp;&amp; $user-&gt;ID == get_current_user_id()) ) {\n\t\t\twp_redirect( home_url() );\n\t\t\texit();\n\t\t}\n\t}\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>You can use the following code snippet to hide user profile from other users.&nbsp; In other words, when implemented, the given code snippet will ensure that only the currently logged-in user can see their profile, and nobody else. As such, viewing &#8220;others&#8217; profiles&#8221; will no longer be possible.&nbsp; Hiding User Profile from Other Users<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"article\/tags":[186,187,188],"article\/categories":[40,7],"class_list":["post-122","gd_place","type-gd_place","status-publish","hentry","gd_place_tags-hide-user-profile","gd_place_tags-dont-show-profile","gd_place_tags-lock-profile","gd_placecategory-code-snippets","gd_placecategory-tips-tricks-more"],"_links":{"self":[{"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/article\/122","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/article"}],"about":[{"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/types\/gd_place"}],"author":[{"embeddable":true,"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/comments?post=122"}],"version-history":[{"count":0,"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/article\/122\/revisions"}],"wp:attachment":[{"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/media?parent=122"}],"wp:term":[{"taxonomy":"gd_place_tags","embeddable":true,"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/article\/tags?post=122"},{"taxonomy":"gd_placecategory","embeddable":true,"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/article\/categories?post=122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}