{"id":2913,"date":"2026-10-20T08:37:21","date_gmt":"2026-10-20T07:37:21","guid":{"rendered":"https:\/\/wpgeodirectory.com\/documentation\/article\/redirect-add-listing-to-login\/"},"modified":"2026-10-20T08:37:21","modified_gmt":"2026-10-20T07:37:21","slug":"redirect-add-listing-to-login","status":"publish","type":"gd_place","link":"https:\/\/wpgeodirectory.com\/documentation\/article\/code-snippets\/redirect-add-listing-to-login\/","title":{"rendered":"How to redirect logged out users from the add listing page to a login page"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">When a logged out visitor opens the add listing page, GeoDirectory shows &#8220;You must login to post.&#8221; with Login and Register links. GeoDirectory does not have its own login system and has no redirect setting for this, but you can change the message or redirect the visitor with a short snippet.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Change the message<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Edit your add listing page and open the GD > Add Listing block settings. In the Login group, change Login Message, and untick &#8220;Show the login and register links if required&#8221; if you do not want the links.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Redirect to your own login page<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This snippet sends logged out visitors from the add listing page to a page of your choice, for example a page with a login form and a registration form side by side. Replace <code>\/login-or-register\/<\/code> with your page&#8217;s address.<\/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() || 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\t$back = geodir_curPageURL();\n\t\twp_safe_redirect( add_query_arg( &#039;redirect_to&#039;, rawurlencode( $back ), home_url( &#039;\/login-or-register\/&#039; ) ) );\n\t\texit;\n\t}\n} );<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>redirect_to<\/code> parameter holds the add listing address. Whether visitors are sent back after logging in depends on your login form: forms that support <code>redirect_to<\/code> will return them to the add listing page.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The snippet does nothing if you have turned on &#8220;Allow posting without logging in?&#8221; in GeoDirectory > Settings > General.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When a logged out visitor opens the add listing page, GeoDirectory shows &#8220;You must login to post.&#8221; with Login and Register links. GeoDirectory does not have its own login system and has no redirect setting for this, but you can change the message or redirect the visitor with a short snippet. Change the message Edit [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"","ping_status":"closed","template":"","meta":{"footnotes":""},"article\/tags":[],"article\/categories":[211,433],"class_list":["post-2913","gd_place","type-gd_place","status-publish","hentry","gd_placecategory-tips-tricks-more","gd_placecategory-code-snippets"],"_links":{"self":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/2913","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=2913"}],"version-history":[{"count":0,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/2913\/revisions"}],"wp:attachment":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/media?parent=2913"}],"wp:term":[{"taxonomy":"gd_place_tags","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/tags?post=2913"},{"taxonomy":"gd_placecategory","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/categories?post=2913"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}