• Hi Tijmen,

    I have added the URL to the store listings and info window through a filter however the web address always shows https:// when the data doesn’t have this.

    Is it possible to remove this using str_replace perhaps? I have tried this but I can’t get it to remove this for the onscreen view.

    Do you have any thoughts at all?

    Thanks
    James

    https://www.ads-software.com/plugins/wp-store-locator/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Tijmen Smit

    (@tijmensmit)

    I tested it, and the same thing happens with me. But I can’t find anything in the code that adds the https://, I would almost start to think that the browser adds the https:// to the url.

    What’s the url of your site?

    Thread Starter James Spencer

    (@js-enigma)

    I have not quite got it live as yet.

    Within the filter I put this into a new variable like this $new_url = str_replace('https://', '', '<%= url %>');

    Then called this like so $info_window_template .= "\t\t" . '<span><a href="<%= url %>">' . $new_url . '</span>' . "\r\n";

    I have tried a few different options to accomplish this including str_replace above and ltrim, both pass the url and show the web address but continue to tag the protocol first. This is fine to actually have as a link but not keen on on showing this on the the front end in this case.

    Could I add the url to the filter for store_meta? If so I am assuming i can add to this?

    add_filter( 'wpsl_store_meta', 'custom_store_meta', 10, 2 );
    
    function custom_store_meta( $store_meta, $store_id ) {
    
        $terms = wp_get_post_terms( $store_id, 'wpsl_store_category' );
    
        if ( count( $terms ) > 1 ) {
            $location_terms = array();
    
            foreach ( $terms as $term ) {
                $location_terms[] = $term->name;
            }
    
            $store_meta['terms'] = implode( ', ', $location_terms );
        } else if ( !empty( $terms ) ) {
            $store_meta['terms'] = $terms[0]->name;
        }
    
        return $store_meta;
    }

    Any help would be appreciated.

    Thanks
    James

    Plugin Author Tijmen Smit

    (@tijmensmit)

    Have you checked the data that is returned with the Ajax request in something like firebug, or another browser console, and checked if it contains the https:// as well?

    If the Ajax response doesn’t contain it, then it has to be the browser that adds the https:// automatically to the url.

    I also just search the wpsl-gmap.js for https://, but the only results are comments.

    Thread Starter James Spencer

    (@js-enigma)

    Hi Tijmen,

    I don’t have firebug installed at the moment but I have looked in firefox developer edition. Hoping I am looking in the correct area but I went into Network > Response and where url is returned all the url’s have https:// prior to the actual web address.

    I am assuming this is therefore returned through the ajax?

    Can you suggest anything I can do to help this?

    Thanks for all your help.
    James

    Plugin Author Tijmen Smit

    (@tijmensmit)

    Ah, I know what happens now. Urls are going through https://codex.www.ads-software.com/Function_Reference/esc_url, and that page says “If the URL appears to be an absolute link that does not contain a scheme, prepends https://.&#8221;

    In that case, you can use the wpsl_store_meta filter to loop through the collected store data, look for the ‘url’ field and remove the https:// again.

    Thread Starter James Spencer

    (@js-enigma)

    Hi Tijmen,

    Glad to see I was on the right lines but I am unsure how to add this to the code for the meta_filter I posted before.

    Can you point me in the right direction at all please?

    Thanks again
    James

    Thread Starter James Spencer

    (@js-enigma)

    Hi Tijmen,

    All sorted now thanks i have had to do the following and would be interested to know if there is a better way to accomplish this.

    Inside the store_meta_filter
    $store_meta['url'] = str_replace("https://", "", $store_meta['url']);

    Then inside the custom_listing_template
    $new_url = str_replace("https://", "", "<%= url %>");

    Plus this to display
    $listing_template .= "\t\t\t\t" . '<span><a href="https://<%= url %>">' . $new_url . '</a></span>' . "\r\n";

    This now shows the web address without the https:// protocol and also maintains the correct link when a user clicks.

    Thanks again
    James

    Plugin Author Tijmen Smit

    (@tijmensmit)

    This code should work, but when I tested it the url without the https:// didn’t work anymore ( at least on my local installation ). So maybe you just need to keep it.

    foreach ( $store_meta as $k => $meta ) {
            if ( $k == 'url' ) {
               $store_meta[$k] = str_replace( 'https://', '', $meta );
            }
        }
    Thread Starter James Spencer

    (@js-enigma)

    HI Tijmen,

    Thanks for the code although for now I will stick with the code I have for now as this seems to work for me at least.

    Thanks again.
    James

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Remove https://’ is closed to new replies.