0

I am using a plugin that uses WP_PLUGIN_URL and that cause mixed content issues.

This is the line of code: <img src="<?php echo esc_url( WP_PLUGIN_URL . '/plugin-name/images/icon1.png' ); ?>">

I can't seem to find an equivalent to produce the same URL.

This is what I tried: <img src="<?php echo esc_url( plugins_url( '/plugin-name/images/icon1.png', dirname(__DIR__))); ?>">

plugins_url() produces: "/wp-content/plugins/plugin-name/front/custom-woo-gallery/plugin-name/images/icon1.png"

content_url() produces: "/wp-content/plugin-name/images/icon1.png"

If this is the wrong approach, how can I resolve the mixed content issue because of WP_PLUGINS_URL

Thanks

2
  • Are your site URLs defined with https? Does the URL in browser also use https?
    – Caleb
    Jun 19, 2023 at 15:17
  • Hi @Caleb URLs in browsers are using https. I use a load balancer to handle the https on frontend. site url and address are not defined in https.
    – PlainH2O
    Jun 19, 2023 at 15:21

1 Answer 1

0

WordPress is expecting http, but you're visiting with https which is causing the mixed content error. Setting your site and address URLs to use https should solve your problem.

If you can't use https in the admin, then you'll need to try ways to tell WordPress to use https only on the frontend. Try something like this (untested):

add_filter( 'site_url', static function ( $url ) {
    if ( is_admin() ) {
        return $url;
    }

    return str_replace( 'http://', 'https://', $url );
} );
6
  • I won't be able to use SSL on the server level. I'm using load balancer to handle front end https.
    – PlainH2O
    Jun 19, 2023 at 15:39
  • SSL at the server level is recommended, but I've updated my answer with a possible solution for changing URLs on frontend only.
    – Caleb
    Jun 19, 2023 at 15:43
  • @Caleb when you are behind load balancer the communication between the balancer and the server is many times over HTTP as there is no point in encription. Jun 19, 2023 at 16:42
  • 1
    @PlainH2O sounds like the opposite solution will be easier, set the site to HTTPS, and convert at the server level at HTTP to HTTPS. This way you will not need to worry about the next plugin that will not be compatible with you non conventional setup Jun 19, 2023 at 16:46
  • 1
    @PlainH2O please read again carefully what I suggested. As for non conventional... wordpress generates URL for the browser, you set it as HTTP to generate URLs that will be easier for the server. whether it is non conventional or not might be a matter of opinion, but not many plugin developers will expect that your site url is wrong on purpose Jun 20, 2023 at 1:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.