Home > Tips and Tricks, Wordpress > Image Path Broken after Changing Permalinks in WordPress

Image Path Broken after Changing Permalinks in WordPress

The Problem

It is common to use relative image paths in your wordpress post. If you put the image files in the images folder of the root directory. Then the path to, say, logo.jpg is coded as

<img src="/images/logo.jpg" />

This works until you change your permalinks. Permalinks change the url to reflect a directory stucture in place of the ugly '?page_id=127', thus breaking the path to images folder.

The Hack

Where you have used relative image paths, replace it with

<img src="<?php echo get_option('siteurl'); ?>/images/logo.jpg" />

This uses your specific siteurl as a prefix to the path of the image.

Hope this helps, it is a great hack.

  1. No comments yet.
  1. No trackbacks yet.