How to Split WordPress Custom Field Values

Snippets by IsItWP

Are you looking for a way to split WordPress custom field value? While there’s probably a plugin for this, we have created a quick code snippet that you can use to split WordPress custom field value in WordPress.

We have been aware of WordPress Post Thumbnail Feature for a while now, but in some cases one is just not enough. This is a cool snippet for expanding WordPress post thumbnail output with the help of custom fields to add more thumbnails. Although there are plugin alternatives, this is a very quick method for something simple, short, and sweet.

So lets say you have a portfolio page and you want to display a couple of thumbnails, say 4(or more). This is what you can do:

Create a custom field value of ‘Images’ and insert the links to your images in the textarea. Each link must be on a new line. Then use this snippet.


All you have to do is add this code to your theme’s single.php file:

$images = get_post_meta($post-&gt;ID,‘Images’);
$images = nl2br($images[0]);
$images = explode(‘&lt;br /&gt;’,$images);
foreach($images as $src) {
	echo "<img src="".trim($src)."" />";

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 19 best WordPress plugins for photographers and how to increase maximum file upload size in WordPress.

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!