How to change links to relative
-
I recently installed an ssl to my website and all of the links in the popular posts recently got force into only https. Is there anyway to change the links to become relative // instead of https:// all the time?
-
I would like to add that this only seems to be occurring for the widget and not the shortcode enabled popular posts page.
Both the shortcode and the widget use the exact same function to retrieve the image URL, so it must be something else.
Post your site’s URL so I can see what’s going on, please.
Thanks you for responding
My website url is Here.
If you look at the side widget, you’ll see that the popular posts thumbnail and title link have https on them even if the page is called with http
Hi there!
Just checked your site. This is the HTML output I see:
<ul class="wpp-list"> <li> <a href="https://yawncentral.com/10-conversation-secrets-everyone-should-know-about/" title="10 Conversation Secrets Everyone Should Know About" target="_self"><img src="https://yawncentral.com/wp-content/uploads/wordpress-popular-posts/5990-80x60.jpg" title="10 Conversation Secrets Everyone Should Know About" alt="10 Conversation Secrets Everyone Should Know About" width="80" height="60" class="wpp-thumbnail wpp_cached_thumb wpp_featured"></a> <a href="https://yawncentral.com/10-conversation-secrets-everyone-should-know-about/" title="10 Conversation Secrets Everyone Should Know About" class="wpp-post-title" target="_self">10 Conversation Secrets Everyone Should Know About</a> <span class="post-stats"></span> </li> <!-- Rest of the code here... --> </ul>
Thumbnails URLs are non-HTTPS. The links to the post are HTTPS.
I’ve never used SSL on a WordPress site before, but it seems that if you want to use SSL on wp-admin only you need to do this.
Edit: I just noticed that the Ajaxify Widget option is enabled on your site. I believe this is why the URLs are using HTTPS instead of HTTP. Could you disable the Ajaxify Widget option to confirm this, please?
I disabled the Ajaxify widget and it did fix the issue with the links.
Thank you for your help. My last question would be concerning the thumbnail URLS. Is there anyway to make the thumbnail URL relative so that it will not trigger ssl security error when the page is loaded with https?
It mixed many of my issues not only with the plugin but including normal thumbnail image URLs. Unfortunately upon further testing, it seems it has broken my image upload capabilities.
I tried to see if I could upload manually to the file manager of my host, however, the uploaded files there do not register itself to the media manager of wordpress.
The first set of codes seems to work fine with the upload. It’s the second set that seems to be creating the issues.
Alright, try changing the second code to this:
function fix_ssl_upload_url( $url ) { if ( !is_admin() ) { if ( is_ssl() ) $url = str_replace( 'https://', 'https://', $url ); return $url; } } add_filter( 'upload_dir', 'fix_ssl_upload_url' );
Alternatively:
- Go to Plugins > Editor and select WordPress Popular Posts from the dropdown at the right.
- Find:
protected function _render_image($src, $dimension, $class, $title = "", $error = null) { $msg = ''; if ($error) { $msg = '<!-- ' . $error . ' --> '; } return $msg . '<img src="' . $src . '" ' . ( false == $this->user_settings['tools']['thumbnail']['responsive'] ? 'width=' . $dimension[0] . ' height=' . $dimension[1] : '' ) . ' title="' . esc_attr($title) . '" alt="' . esc_attr($title) . '" class="' . $class . '" />'; } // _render_image
… and change it to:
protected function _render_image($src, $dimension, $class, $title = "", $error = null) { $msg = ''; if ($error) { $msg = '<!-- ' . $error . ' --> '; } return apply_filters( 'wpp_render_image', $msg . '<img src="' . $src . '" ' . ( false == $this->user_settings['tools']['thumbnail']['responsive'] ? 'width=' . $dimension[0] . ' height=' . $dimension[1] : '' ) . ' title="' . esc_attr($title) . '" alt="' . esc_attr($title) . '" class="' . $class . '" />' ); } // _render_image
- Hit the Update file button to save changes.
- Then, add this code to your functions.php:
function remove_protocol( $image ){ return preg_replace( '/(https?):/','', $image ); } add_filter('wpp_render_image', 'remove_protocol');
If you decide to go for the alternative solution above, you no longer need the two functions I suggested earlier.
When I used the second code it would let me upload however, it’s an empty attachment file that would show up.
The alternative code you gave me did do anything unfortunately. I had some errors, but I was able to restore it back to working condition.
I was thinking since what you did with the second code is essentially tell it to only run the string replacement when the user is not admin. Would it work if I just try to make it run if the user is a subscriber? I am only planning on turning on the https when a user logs in to the website so that their session is secure. Would this modification work?
function fix_ssl_upload_url( $url ) { global $current_user; get_currentuserinfo(); if ( user_can( $current_user, "subscriber" ) ) { if ( is_ssl() ) $url = str_replace( 'https://', 'https://', $url ); return $url; } } add_filter( 'upload_dir', 'fix_ssl_upload_url' );
The plugin modification I suggested removes http/https from thumbnails’ URL. That way, images will load correctly under https.
What errors did you get?
I got an error after trying to change back the wordpresspopular.php to its default. It kept deactivating. Turns out I left a space after ?> in the fuctions.php after deleting the function associated with it.
I didn’t close the the browser and restart, after modifying your plugin mostly because I was being cautious of messing up. I will give it another try and do a full cache refresh and I’ll let you know how it goes.
O wow it totally does work now, and I can upload images. And all the pages have a lock icon. Though looks like I still need the first function to keep my themes thumbnail URLs generation to stay relative.
Thank you so much for helping me with this. You are awesome :p A++++
- The topic ‘How to change links to relative’ is closed to new replies.