How to Remove HTML from Shortcode

  • Najeeb
    Najeeb
    Newbie 13 points
    May 14, 2015 at 8:54 pm

    I am trying to use [LOCATION] shortcode to display address. I don’t want to display HTML which renders with the shortcode

    <span class=”wlt_shortcode_location”>Los Angeles, CA 90057, United States <i class=”fa fa-info-circle wlt_pop_location_37″ style=”cursor:pointer;” rel=”popover” data-placement=”top” data-original-title=”Useful Links” data-trigger=”hover”></i></span>

    So it outputs just the address as Los Angeles, CA 90057, United States

    Same for the [MAP-ZIP] as well.

    Any help?

    Many Thanks

  • Hemanta Chakladar
    Hemanta Chakladar
    Super Guru 1,710 points
    May 15, 2015 at 3:21 am

    You can create a new shortcode for that, just copy the function for the [LOCATION] shortcode and remove the html part from their. Then use your new shortcode in place of currently using [LOCATION]

  • Najeeb
    Najeeb
    Newbie 13 points
    May 17, 2015 at 12:09 am

    Thanks Hemanta, Which file do I need to change, I checked the class_shortcodes but no luck.

  • Mark
    Mark
    Titan 733 points
    May 18, 2015 at 12:32 pm

    Have you tried using the [map_location] instead?

    Mark

  • Najeeb
    Najeeb
    Newbie 13 points
    May 21, 2015 at 10:16 am

    Hi Mark, yes I did but same with this one too. I really need to know how to get the address out of shortcode with out any HTML. Anyone out there could help?

    Thanks

  • Hemanta Chakladar
    Hemanta Chakladar
    Super Guru 1,710 points
    May 21, 2015 at 10:59 am

    As said above , use [map_location] lower case !!!

  • Hemanta Chakladar
    Hemanta Chakladar
    Super Guru 1,710 points
    May 21, 2015 at 11:01 am

    Does [LOCATION] shortcode exist ? I can’t found it shortcodes.php

  • Najeeb
    Najeeb
    Newbie 13 points
    May 21, 2015 at 1:58 pm

    I tried [map-location] but it renders as :

    <span class=”wlt_shortcode_map_location”>Riverside, CA, United States</span>

    How can I remove the <span> part from it ?

    Thanks

  • Najeeb
    Najeeb
    Newbie 13 points
    May 21, 2015 at 2:35 pm

    Ok did some research on Google and found this solution which works for me:

    <script>
    var html = ‘[map_location]’;
    var div = document.createElement(“div”);
    div.innerHTML = html;
    var text = div.textContent || div.innerText || “”;
    alert(div.innerText);
    </script>

    Thanks
    Najeeb


  • Josh
    Super Guru 13,875 points
    May 21, 2015 at 2:45 pm

    (Sorry Late response)
    @Najeeb
    Not sure why you want to remove the <span> but anyway,if using the [LOCATION] shortcode then try this in Theme Options >Design Setup >Custom Meta Data >Footer Styles
    [code title=””]
    <script>
    jQuery(“.wlt_shortcode_location”).contents().unwrap();
    </script>
    [/code]
    @Hemanta
    The [LOCATION] shortcode does exist

  • Hemanta Chakladar
    Hemanta Chakladar
    Super Guru 1,710 points
    May 21, 2015 at 2:52 pm

    @Josh, why [LOCATION] shortcode in not listed in shortcodes.php ?


  • Josh
    Super Guru 13,875 points
    May 21, 2015 at 2:59 pm

    @Hemanta it is listed in the file class_shortcodes.php.Try doing a search in the file

  • Hemanta Chakladar
    Hemanta Chakladar
    Super Guru 1,710 points
    May 21, 2015 at 3:07 pm

    I have 3 search result for the keyword LOCATION, which one is for the [LOCATION] ?

    Attachments:
    You must be logged in to view attached files.
  • Najeeb
    Najeeb
    Newbie 13 points
    May 21, 2015 at 4:27 pm

    @Josh
    First of all thank you very much for coming up with a solution !!

    Actually I am working on a property rental website and I am integrating walkscore app which requires a javascript code to be added to the place where you want the map to appear. This code requires address of the location, this is where I was trying to use the [location] shortcode. But because the shortode carries HTML, the map keeps breaking.

    I have now used the javascript I mentioned above in isolation for this place only and it worked. If I add the script or the codes you mentioned above within the header of footer, it will remove the HTML from shortcode sitewide which I don’t want.

    @ Hemanta
    I also tried to find the [location] shortcode in the files but couldn’t. But as the shortcode exists the codes must be present somewhere in the files, still looking.

    Thanks
    Najeeb

  • Mark
    Mark
    Titan 733 points
    May 21, 2015 at 9:14 pm

    @Najeeb, I needed a similar feature where I could output a custom field without the span and class added to it. I tried to modify core files, but that somehow broke my site so had to revert it back from backup. When I almost gave up, I found a plugin that can extract value of any custom field as a shortcode. You simply use [customfield name=”custom_field_name”]
    (where you replace the ‘custom_field_name’ with the name of your custom field).
    So in your case you would simply use [customfield name=”map_location”] and it will give you the value without any extra code or formatting.

    Been using it for almost a year now and it is working a treat. Shame I did not find it earlier, could have saved me a lot of time and headaches (and I would have possibly more hear on my head).

    You can find it here:
    https://premiumwebservices.co.uk/shop/premiumpress-plugins/custom-fields-shortcodes/

    Mark

    This reply was awarded the best answer by the topic poster.
Viewing 15 posts - 1 through 15 (of 15 total)

New Business Themes for WordPress 2020

Start your new website today!

View Business Themes