Posted on

IFTTT with custom URLs using WordPress


If This Than That (IFTTT) is a great service allowing to connect a lot of different web services. Still it would be great to have the option to open up a custom URL to get your own stuff running. Over here we are using a WordPress installation to implement an enhancement to do exactly that.

How it works

Coming later …

Extend WordPress with some small code

This feature uses the possibility that IFTTT can automatically create a post. Therefore we add this additional code within the function.php file.

function process_ifttt($post_id, $post, $post_before){
	// check if this post was already processed
	$meta_ifttt = get_post_meta( $post_id, 'ifttt', true );
	if ($meta_ifttt == '') {
		$post_content = $post->post_content;

		// find all ifttt tags
		preg_match_all('#\[ifttturl:(.*?)\]#i', $post_content, $res);

		// open the url(s) and get the first 1000 chars
		if (is_array($res[1])) {
			$response = '';
			$processed = false;
			foreach ($res[1] as $url) {
				if (strstr($url, 'http')) {
					$response .= file_get_contents($url, NULL, NULL, 0, 1000) . "\n\r###\n\r";
					$processed = true; 
			if ($processed) {
				add_post_meta($post_id, 'ifttt', true, true);
				add_post_meta($post_id, 'response', $response, true);
				// send the post to trash or delete
				wp_trash_post( $post_id  );
				// wp_delete_post( $post_id, true  );
add_action( 'post_updated', 'process_ifttt', 10, 3 );

Create a user in WordPress

We want to make sure that only a specific user is allowed to use this feature and therefore we create a new WordPress user for this purpose. Open up your WordPress admin page and go to Users > Add New. Now enter a new user (e.g. “ifttt”) with the Author role and assign a password (e.g. “iftttpass”). You will need this login information for your IFTTT connection.

Configure IFTTT

Within your IFTTT profile add a new WordPress channel with the information of your WordPress user.

Blog URL:
Username: ifttt
Password: iftttpass

Create a recipe within IFTTT

Now you are ready to create a recipe for IFTTT where you can open up an customer URL. Create a recipe where your action is using “WordPress > Create a Post”. The title of the post does not matter at all and within the body you can add the tag [ifttturl:]. Whenever this action is started the specified URL will be opened up automatically.