• Resolved David

    (@buy4me)


    Hi, i need a little help here.

    Because i have a lot of lost images i use this plugin. But i want that when a broken image to do redirect to custom url the whole post.

    Any help?

    Thanks

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

    (@room34)

    This plugin is just removing <img> tags that are returning a 404 error for the src URL. I’m not really sure how/why you’d want to have a redirect in that situation. Or do you mean you want to have it load a standard placeholder image in that <img> tag instead of removing it altogether from the DOM? I’m considering that as an option in a future update.

    Thread Starter David

    (@buy4me)

    Hi. My site is with jokes content and some of this jokes are typed on images..
    If the img is missing this is not so good for the visitors expierience

    So to avoid that problem is better for me to redirect if broken img is found..

    Plugin Author room34

    (@room34)

    OK, that makes sense. I think you can see though that the idea of having the entire post redirect to the home page because an image is missing is definitely an edge case for what this plugin is intended to do. Generally images are not the substantive content of a post… at least not to the extent that the post shouldn’t even be shown to the user if the image is missing.

    That said, at the very least I could add a custom jQuery hook into the plugin to allow for different handling than the default behavior. Then some additional jQuery code in your theme would allow the plugin to trigger a location.replace() to send the user to the home page instead of displaying the post.

    Thread Starter David

    (@buy4me)

    Thank you. Instant of redirection to home page i have a link that drives the users in random post.

    https://example.com/?bimber_random_post=true

    Plugin Author room34

    (@room34)

    OK, this was a pretty simple addition. Version 1.4.0 is available now.

    I made it flexible so you can write your own custom jQuery around the new r34rbi_missing_image event. However, if you just want it to redirect to the home page, I leveraged that with a new PHP filter as well, so you can just add this line of code to your theme’s functions.php file:

    add_filter('r34rbi_redirect_on_missing_image', '__return_true');

    Instead of using the built-in __return_true callback, you can also write your own custom callback function to return a different URL for the redirect.

    Thread Starter David

    (@buy4me)

    Thanks. I have no idea from coding for that you say for adding my JQuery. But if the
    { $redirect_on_missing_image = home_url('/'); }

    that the redirects good to home page.

    If i change to
    { $redirect_on_missing_image = home_url('/?bimber_random_post=true'); }
    or
    { $redirect_on_missing_image = home_url('https://example.com/?bimber_random_post=true'); }

    then the page is reloading, and reloading and reloading all the time to random posts

    • This reply was modified 11 months, 1 week ago by David.
    Thread Starter David

    (@buy4me)

    Thank you is working good. I tested on my general site and is working good.

    You make my day thank you again.

    Plugin Author room34

    (@room34)

    Don’t change any code directly in the plugin. You should write your own function in your theme’s functions.php file, that just returns the URL you want to redirect to, e.g.:

    function my_redirect_function() { return 'https://example.com'; }

    …and then call that function like this:

    add_filter('r34rbi_redirect_on_missing_image', 'my_redirect_function');

    (This probably isn’t going to solve the issue you’re mentioning; I just want to point it out as the proper way to customize the logic.)

    I don’t have access to the redirection method you’re using (looks like it’s maybe part of your theme), but I tested these changes with the Better Random Redirect plugin (setting the “random” URL as the return value for my redirect function), and it is working properly.

    Thread Starter David

    (@buy4me)

    Is working fine. Thank you again

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘If broken image redirect’ is closed to new replies.