{"id":2368,"date":"2026-10-20T08:32:19","date_gmt":"2026-10-20T07:32:19","guid":{"rendered":"https:\/\/wpgeodirectory.com\/documentation\/article\/redirect-logged-out-users-from-add-listing-to-login\/"},"modified":"2026-10-20T08:40:21","modified_gmt":"2026-10-20T07:40:21","slug":"redirect-logged-out-users-from-add-listing-to-login","status":"publish","type":"gd_place","link":"https:\/\/wpgeodirectory.com\/documentation\/article\/how-tos\/redirect-logged-out-users-from-add-listing-to-login\/","title":{"rendered":"How to send logged out users to the login page from Add Listing"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">When a logged out visitor opens the Add Listing page, GeoDirectory shows the message &#8220;You must login to post.&#8221; with Login and Register buttons under it. It does not redirect them on its own. You can keep that message and make it clearer, or add a small snippet that sends them straight to the login page and back to the form once they are signed in.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Show login and register buttons on the Add Listing page<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The GD &gt; Add Listing block, widget and shortcode has a setting called &#8220;Show the login and register links if required&#8221;. It is on by default, and you can change the message with the Login Message setting. In shortcode form:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-markup\">&#091;gd_add_listing show_login=&#039;1&#039; login_msg=&#039;Please log in or create a free account to add your business.&#039;&#093;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The Login button links to <code>wp_login_url()<\/code> with the Add Listing page as the return address. With UsersWP active, that link goes to your UsersWP login page and carries a <code>redirect_to<\/code> parameter, so after logging in the user lands back on Add Listing.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Redirect logged out users automatically<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If you would rather skip the message, add this snippet with the <a href=\"https:\/\/wpgeodirectory.com\/documentation\/article\/useful-plugins\/code-snippets-plugin\/\">Code Snippets plugin<\/a> or your child theme&#8217;s functions.php. It only runs on the page set as the Add Listing page (or any page containing the <code>&#091;gd_add_listing&#093;<\/code> shortcode) and does nothing if you allow posting without logging in.<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\">add_action( &#039;template_redirect&#039;, function() {\n\tif ( is_user_logged_in() || ! function_exists( &#039;geodir_is_page&#039; ) ) {\n\t\treturn;\n\t}\n\n\t\/\/ Leave it alone if guests are allowed to post.\n\tif ( geodir_get_option( &#039;post_logged_out&#039; ) ) {\n\t\treturn;\n\t}\n\n\tif ( geodir_is_page( &#039;add-listing&#039; ) ) {\n\t\twp_safe_redirect( wp_login_url( geodir_curPageURL() ) );\n\t\texit;\n\t}\n} );<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Because the snippet passes the current URL, a link such as <code>\/add-listing\/?listing_type=gd_place<\/code> brings the user back to the same post type after login.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">New users who register first<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Registration is a separate step. UsersWP sends new users to the page set in its register redirect setting, unless the register request includes a <code>redirect_to<\/code> value. If most of your visitors need to register before they post, set the register redirect to your Add Listing page.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you prefer to only change the menu, a plugin that shows menu items by login status lets you give logged out users a link to <code>\/login\/?redirect_to=https:\/\/example.com\/add-listing\/<\/code> and logged in users a link to the Add Listing page itself. Replace the paths with your own login and Add Listing pages.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When a logged out visitor opens the Add Listing page, GeoDirectory shows the message &#8220;You must login to post.&#8221; with Login and Register buttons under it. It does not redirect them on its own. You can keep that message and make it clearer, or add a small snippet that sends them straight to the login [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"article\/tags":[],"article\/categories":[211,432],"class_list":["post-2368","gd_place","type-gd_place","status-publish","hentry","gd_placecategory-tips-tricks-more","gd_placecategory-how-tos"],"_links":{"self":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/2368","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article"}],"about":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/types\/gd_place"}],"author":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/comments?post=2368"}],"version-history":[{"count":2,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/2368\/revisions"}],"predecessor-version":[{"id":2650,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/2368\/revisions\/2650"}],"wp:attachment":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/media?parent=2368"}],"wp:term":[{"taxonomy":"gd_place_tags","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/tags?post=2368"},{"taxonomy":"gd_placecategory","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/categories?post=2368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}