IT Blog

  • Blog
  • Technology
    • Technology
    • Architecture
    • CMS
    • CRM
    • Web
    • DotNET
    • Python
    • Database
    • BI
    • Program Language
  • Users
    • Login
    • Register
    • Forgot Password?
  • ENEN
    • 中文中文
    • ENEN
Experience IT
In a World of Technology, People Make the Difference.
  1. Home
  2. Technology
  3. CMS
  4. Wordpress
  5. Fixing image issue in posts

Fixing image issue in posts

2019-02-08 1448 Views 0 Like 1 Comments

Table of Contents

  • Issue
  • Reason
  • Solution

Issue

For article collection site, many articles are copied from other websites. Very often, images were not displayed.

Reason

Some image servers switching their protocol between http and https.

Solution

1. Add a general function imgError. You could add it from 'Custom CSS & JS' plugin if it was installed.

function imgError(image) {
    image.onerror = "";
    if(image.src.startsWith('http:')) image.src=image.src.replace(/^http:\/\//i, 'https://');
    if(image.src.startsWith('https:')) image.src=image.src.replace(/^https:\/\//i, 'http://');
}

2. Add onerror event to all img tags.

<img onerror="imgError(this);" src= ...>

Modify existing posts to apply this solution:

UPDATE wp_posts set post_content=replace(post_content,'<img ','<img onerror="imgError(this);" ');

Done.

TODO: add js script to add onerror event to all img tags dynamically.

Loading

error
fb-share-icon
Tweet
fb-share-icon
IT Team
Author: IT Team

Tags: None
Last updated:2019-02-08

IT Team

This person is lazy and left nothing

Like
< Previous
Next >

Comments

  • IT Team

    Improved version:

    Switch external image for index page and posts

    2019-04-11
    Reply
  • Cancel reply
    Newest Hotspots Random
    Newest Hotspots Random
    Rich editor not working Making web page scroll down automatically Getting data from Dapper result All Unicode Chars How to keep and display contact form 7 data Common Regular Expressions
    Creating dynamic weekly report in T-SQL Crawling images from web with PHP Apostrophe 2 title font is too big Common Regular Expressions Get horizontal data from "contact-form-7-to-database-extension" plugin HTML Symbols: Math
    Categories
    • Architecture
    • BI
    • C#
    • CSS
    • Database
    • DotNET
    • Hosting
    • HTML
    • JavaScript
    • PHP
    • Program Language
    • Python
    • Security
    • SEO
    • Technology
    • Web
    • Wordpress

    COPYRIGHT © 2021 Hostlike IT Blog. All rights reserved.

    This site is supported by Hostlike.com