change location
This topic contains 26 replies, has 3 voices, and was last updated by Strong Coffee 9 years, 9 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support TicketTagged: location
-
AuthorPosts
-
February 9, 2015 at 9:21 pm #30477
On your demo site you have an option to Change Location in your header that lets you select the country/region/city. How do you add that? Can it be added to the sidebar?
February 9, 2015 at 9:25 pm #30479Hello, to enable the location switcher, first create a menu in Appearance/menu, then link it to GD going to Geodirectory/Design and in the navigation tab select your menu, and then go to the MultiLocation settings and rich the option where it says “Show location switcher in menu”
to add it in your sidebar, or wherever you want, you can insert this shortcode
[geodir_location_tab_switcher autoredirect="1"]
in a text widget
February 10, 2015 at 4:49 pm #30571Is there a way to just show the city using the shortcode?
February 10, 2015 at 5:23 pm #30577I believe you can use this in your template
$current_location = geodir_get_current_location(); echo $current_location ;
and it will show only the city, but this needs to be inserted inside a function or in the child theme
February 10, 2015 at 5:50 pm #30579or create a shortcode and use it anywhere by adding this in your active theme functions.php
// Add Shortcode function gd_curr_loc_shortcode() { // get the location $current_location = geodir_get_current_location(); // return the location return $current_location ; } add_shortcode( 'gd_curr_location', 'gd_currlocation_shortcode' );
than use shortcode [gd_curr_location].
Haven’t tested so use with care…
Thx
February 10, 2015 at 7:06 pm #30596Added the code to my child theme’s function.php file then added the shortcode to my sidebar widget and it just displays “[gd_curr_location]” in the sidebar.
February 10, 2015 at 7:06 pm #30597This reply has been marked as private.February 10, 2015 at 7:48 pm #30602you need to make your widgets shortcode ready. In wordpress shortcode are ment to be used in content area of posts and pages.
Add this to your functions.php
add_filter('widget_text', 'do_shortcode');
Thx
February 10, 2015 at 8:40 pm #30620Still get the shortcode displaying as text on the page. Here’s what I added to my functions.php file:
add_filter(‘widget_text’, ‘do_shortcode’);
// Apply filter
add_filter(‘body_class’, ‘gd_body_classes’);function gd_body_classes($classes) {
if (geodir_is_geodir_page()) { $classes[] = ‘this_is_a_gd_page’;
return $classes;}
}// Add Shortcode
function gd_curr_loc_shortcode() {// get the location
$current_location = geodir_get_current_location();
// return the location
return $current_location ;}
add_shortcode( ‘gd_curr_location’, ‘gd_currlocation_shortcode’ );February 10, 2015 at 9:06 pm #30623There was an error in the code provided and actually there was a much easier way to do it:
add_shortcode( 'gd_curr_location', 'geodir_get_current_location' );
Than use [gd_curr_location] to call the shortcode.
However this will only show the location once a location has been set and without the Location Switcher you will never be able to set one…
Once you add the location switcher allowing users to set a location, that text widget will show the location name…
Thx
February 11, 2015 at 5:12 pm #30699Sorry – I’m confused. So basically their isn’t a way to just show the city?
February 11, 2015 at 5:18 pm #30701Not until you set one with the location switcher.
February 11, 2015 at 7:54 pm #30726i’ve added both the shortcodes to my sidebar [geodir_location_tab_switcher autoredirect=”1″] and [gd_curr_location] but i only see the location switcher with country/region/city even after i select a location from the location switcher.
February 12, 2015 at 10:42 pm #30802Hi,
I just tested this here: wpgeo.directory/
and after you select a location via location switcher, the location name appears at the bottom of the sidebar, but because that function is echoing the output and shortcodes best practice would require to return the output, it is breaking the widget html appearing before the title.
I’ll ask Stiofan if he can think of anything.
Thx
February 13, 2015 at 3:38 pm #30822Ok,
obviously our wizard had the solution:
// Add Shortcode for current location name function geodir_current_loc_shortcode() { ob_start(); geodir_get_current_location(); $output = ob_get_contents(); ob_end_clean(); return $output; } add_shortcode( 'gd_current_location_name', 'geodir_current_loc_shortcode' );
This is being added to next core release, so before updating next time, make sure to remove the code from your child theme or it will throw an error.
Thanks
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket