I'm trying to get an element from it's URL.

For example, say we have a url of http://craft.dev/blog/article1. Is there a function I can call within a plugin and pass over blog/article1 that will return a corresponding element, if one exists, for that specific URL? I'm sure there is a way to do this with the router, I'm just not sure what it is.

1 Answer 1


Try using ElementsService:

$entry = craft()->elements->getElementByUri( 'blog/article1' );
  • That was a whole lot easier then I expected. I was looking on the routing services, did not even think to look on the element service. Thank you! Mar 5, 2015 at 23:56
  • No worries – it's often like that with Craft, no? :) Mar 6, 2015 at 0:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.