Get Post ID from Tumblr URL in PHP

This little code snippet can be used to get ID of a Tumblr post if you have URL of post, no matter if there is unique slug at the end (http://staff.tumblr.com/post/122809548365/apologies-for-the-disruption-some-of-you) or not (http://staff.tumblr.com/post/122809548365), or if it’s on custom domain (http://van-life.net/post/120576266146/thecindercone-a-video-i-made-with-some-help).

Can be useful when you have to deal with Tumblr API.


$full_url = 'http://staff.tumblr.com/post/122809548365/apologies-for-the-disruption-some-of-you';
$path = parse_url( $full_url, PHP_URL_PATH );
$path_components = explode( '/', trim( $path, '/' ) );
$tumblr_post_id = $path_components[1];
Post navigation

Leave a Reply

Comment Guidelines:

  • Fields marked with * are required
  • If you want your picture next to comment, open an account at Gravatar
  • If you want to know if someone replied to your comment, check “Notify me of followup comments via e-mail”
  • You can use these HTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Your email address will not be published. Required fields are marked *

Post navigation