How Do I Change the Position of an Image in WordPress?

If you would like to move an image within a WordPress post or page, you can use the wp_insert_image() function. This function takes three arguments: the post ID, the image filepath, and the position.

The position argument can be one of the following values: “before”, “after”, or “middle”. The function will then move the image to the specified position within the post or page.

To move an image to the before position, use the before argument:

wp_insert_image(3, ‘/images/logo.png’, before);

To move an image to the after position, use the after argument:

wp_insert_image(3, ‘/images/logo.png’, after);

To move an image to the middle position, use the middle argument:

wp_insert_image(3, ‘/images/logo.png’, middle);

If you would like to move an image within a post or page, but do not want to overwrite any existing image content, you can use the wp_insert_image() function with the no_overwrite argument. This will return the image content as is, without overwriting any existing content.

To move an image to the before position, use the no_overwrite argument:

wp_insert_image(3, ‘/images/logo.png’, before, no_overwrite);

To move an image to the after position, use the no_overwrite argument:

wp_insert_image(3, ‘/images/logo.png’, after, no_overwrite);

To move an image to the middle position, use the no_overwrite argument:

wp_insert_image(3, ‘/images/logo.png’, middle, no_overwrite);

Conclusion

In this article, we’ve demonstrated how to use the wp_insert_image() function to move an image within a WordPress post or page. If you would like to learn more about working with images in WordPress, be sure to check out the WordPress Codex.