Remove http://
-
Hi Tijmen,
I have added the URL to the store listings and info window through a filter however the web address always shows http:// 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
-
I tested it, and the same thing happens with me. But I can’t find anything in the code that adds the http://, I would almost start to think that the browser adds the http:// to the url.
What’s the url of your site?
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('http://', '', '<%= 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
JamesHave 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 http:// as well?
If the Ajax response doesn’t contain it, then it has to be the browser that adds the http:// automatically to the url.
I also just search the wpsl-gmap.js for http://, but the only results are comments.
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 http:// 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.
JamesAh, I know what happens now. Urls are going through https://codex.wordpress.org/Function_Reference/esc_url, and that page says “If the URL appears to be an absolute link that does not contain a scheme, prepends http://.”
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 http:// again.
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
JamesHi 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("http://", "", $store_meta['url']);Then inside the custom_listing_template
$new_url = str_replace("http://", "", "<%= url %>");Plus this to display
$listing_template .= "\t\t\t\t" . '<span><a href="http://<%= url %>">' . $new_url . '</a></span>' . "\r\n";This now shows the web address without the http:// protocol and also maintains the correct link when a user clicks.
Thanks again
JamesThis code should work, but when I tested it the url without the http:// 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( 'http://', '', $meta ); } }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
The topic ‘Remove http://’ is closed to new replies.