Executing Custom PHP Functions

You can execute any PHP function (native functions, or user-defined functions) from inside any text box (post title, post content, Custom Field values, etc.) of WP All Import. You can pass values from your data file to the PHP function.

Example 1 – using the native str_replace function to remove commas

Here, we’re using the str_replace function to remove commas from the post title:

[str_replace(",", "", {title[1]})]

Note the use of the double quotes instead of single quotes. You must use double quotes when executing PHP functions from within WP All Import. You can’t use single quotes.

Example 2 – using a user defined function

WP All Import has a built-in Function Editor where you can write your own custom functions. You can access the Function Editor when editing your import template, or via All Import > Settings in your WordPress dashboard.

Here’s why you should use the Function Editor:

  • Syntax highlighting
  • Built-in syntax validator to prevent site-breaking code errors
  • The code only runs during an import
  • Very easy to update the code and test it using the “Preview” feature in the content area of an import template

As an example, let’s assume that you’re importing products into WooCommerce, and each product has a comma separated list of image URLs. The problem is, while each image has been uploaded to a different folder, they all have the same filename:


So by default, only the first image would be imported (as the other images would be considered copies of the same image, due to the filenames).

You can resolve this by writing your own custom PHP function to process the image URLs, give each image an alternative filename, and then return the new list of image URLs.

Here’s an example of a function that you could use:

function my_fix_img($list) {
	$array = explode(",", $list);

	$result = array();

	foreach ($array as $item) {
		$result[] = $item . '#/' . substr( md5( $item ), 0, 8 ) . ".png";

	return implode(",", $result); 

Once you’ve inserted this code into the Function Editor:

You would then call it in the “Images” section, like this: