Shortcodes in listing tabs
This topic contains 11 replies, has 4 voices, and was last updated by Mitch Canton 8 years, 1 month ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support TicketTagged: shortcodes, tabs
-
AuthorPosts
-
October 21, 2016 at 8:49 am #289070
I had gotten some info in a presale question. It didn’t work in testing, so I moved on, but now that I have purchased a membership, I need to get it resolved.
Shortcodes are not working in some of my Detail Listing tabs. I thought I had gotten Shortcodes to work in some custom field tabs I created, but now they’re not, and they do not work in the default Special Offers tab.
I was given code at these two pages,
https://gist.github.com/Stiofan/00ce073d12a1df0c6f4d8f413936bd71
https://gist.github.com/Stiofan/b3d37f2899c6b36d3d6c9eebdc37abc1but I tried them to no avail. Do I use one or both? I would have thought both would have conflicted? I can simply add whichever to functions in my child theme and it should work, right?
In searching I also found this: https://wpgeodirectory.com/add-a-new-tab-in-the-listing-detail-page/
But can’t I just add a tab in the backend vs. needing to add that to functions for multiple tabs?
Guidance on how to resolve?
Thanks.
October 21, 2016 at 9:29 am #289082Hi Mitch,
I think you’re referring to this post https://wpgeodirectory.com/support/topic/using-other-shortcodes-inside-place-custom-fields/ . Do you think you can share WP temp admin access to your site so we can take a better look? You can post the details here using the private reply option below.
Thanks!
October 21, 2016 at 5:02 pm #289317Hi Kor,
No, I was referring to the posts I had linked. But that post provided much of the same info. So I started from scratch, with the code you supplied there (in functions.php), but it still does not apply the shortcode to the fields. I have tried in both at text and textarea.
I’m not sure why it is not working, so you can have a look and see what I may have done wrong.
Thanks.
October 21, 2016 at 5:04 pm #289319This reply has been marked as private.October 21, 2016 at 5:09 pm #289321This reply has been marked as private.October 22, 2016 at 3:00 am #289533Shortcodes can only work in HTML custom fields.
1) I created an HTML custom field called “Guust” with variable “guust”
Make sure it is admin only, allowing users to add shortcodes is risky.2) Then I added this code to functions.php
add_filter(‘geodir_tab_show_geodir_guust’,’my_enable_shortcodes_on_field’,10,2);
function my_enable_shortcodes_on_field($html, $variables_array){
return apply_filters(‘the_content’, $html);
}3) Then add a shortcode to that field.
There is some redirection going on I do not understand, so try turning off all plugins you do not need in your sandpit and see how you go. It works on my test site, but I do not have all your other plugins.
October 23, 2016 at 7:29 pm #290275Hey Guust,
Thanks for taking a look. I’m having quite a runaround with that redirect issue you mentioned, but I think I’ve got it figured. Back to the shortcodes first.
I was told that shortcodes could work in text/textarea fields. I was sent here: https://gist.github.com/Stiofan/00ce073d12a1df0c6f4d8f413936bd71
during a presales email thread, which gives:<?php function my_enable_shortcodes_in_cf($html,$location,$cf){ // this line will enable it for all text inputs $html = do_shortcode( $html ); return $html; } add_filter('geodir_custom_field_output_text','my_enable_shortcodes_in_cf',15,3);
Is this not the case?
And with respect to your html CF code, if I were to have multiple extra tabs for shortcodes, would I then need to change the code you have in item (2) to somehow add those?
Thank you.
October 23, 2016 at 9:50 pm #290337I do now have shortcodes working in ‘text’ fields.
After some trial and error and error, 🙂 I also figured out a way to add a second tab (by simply adding something like this):
add_filter('geodir_tab_show_geodir_newest','my_enable_shortcodes_on_field_2',10,2); function my_enable_shortcodes_on_field_2($html, $variables_array){ return apply_filters('the_content', $html); }
That is probably totally NOT the right way to do it, so please LMK a better way to do multiple tabs.
Lastly, the placement of shortcode in these new areas do NOT render the related content in the “Details Page Sidebar” when that area is selected in the ‘Show in what locations’ box. How to I resolve?
Thanks!
October 23, 2016 at 10:22 pm #290342My understanding is that in the latest version, you do not need to add that function anymore. You can add shortcodes to any html field, but you need to use the code I used to tell what field will accept shortcodes. Allowing users to add shortcodes is a security risk.
To add tabs, review this https://wpgeodirectory.com/docs/core-place-settings/#fieldset
I’ll get the developers to confirm and review your question after the weekend.
October 23, 2016 at 11:16 pm #290371I pulled that – function my_enable_shortcodes_in_cf($html,$location,$cf) – code from my custom WPGD plugin, and the fields that *were* rendering shortcodes stopped working. So I’m not really sure, but it seems to still need it? (We have 1.6.10 installed).
(edit) I just triple-checked with and without that function code, and it works with the code active and does not with the code removed.
I totally agree with your comment about shortcodes being added by users.
Is the admin-only setting something that precludes the display of shortcode in the Detail Page Sidebar? I tried two fields, one admin-only=yes, one=no, but neither displayed the shortcodes in the Sidebar (although they did display in the tabs). Both were set to show in both places in the ‘Show in what locations’ box.
What needs to happen to get shortcodes to display in the detail page sidebar too?
Thanks for your timely replies and your access on the weekend. Have a great day.
October 24, 2016 at 9:22 am #290527The special offers in its own tab requires its own hook
add_filter('gd_special_offers_content','my_enable_shortcodes_in_cf',10,1);
You CAN enable shortcodes on any type of field, the example i gave you was for a text field, this would be for textarea AND text input
function my_enable_shortcodes_in_cf($html,$location,$cf){ // this line will enable it for all text inputs $html = do_shortcode( $html ); return $html; } // Enables for textarea add_filter('geodir_custom_field_output_textarea','my_enable_shortcodes_in_cf',15,3); Enabled for text input add_filter('geodir_custom_field_output_text','my_enable_shortcodes_in_cf',15,3);
Thanks,
Stiofan
October 24, 2016 at 3:48 pm #290858Thanks guys, excellent support. I’m new here, but great impression so far. 🙂
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket