<p>Try using <a href="http://buildwithcraft.com/classreference/services/ElementsService#getElementByUri-detail" rel="nofollow">ElementsService</a>:</p>

<pre><code>$entry = craft()-&gt;elements-&gt;getElementByUri( 'blog/article1' );
</code></pre>

CC BY-SA 3.0
2015-03-05T23:56:27.420Z
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!
Nicholas LeBlanc
CC BY-SA 3.0
2015-03-06T00:11:52.580Z
No worries – it's often like that with Craft, no? :)
Mats Mikkel Rummelhoff
CC BY-SA 3.0
2015-03-05T23:33:44.770Z
2015-03-05T23:33:44.770Z
Mats Mikkel Rummelhoff
<p>I'm trying to get an element from it's URL. </p>

<p>For example, say we have a url of <code>http://craft.dev/blog/article1</code>. Is there a function I can call within a plugin and pass over <code>blog/article1</code> 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.</p>

<plugin-development><url><localization>
Lookup element by URL
# Lookup element by URL

(Asked by: username_0 on 2015-03-05)

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.

**Tags:** plugin-development, url, localization


---

## 1 answers

### Answer by username_1 on 2015-03-05. Score: 2 | Accepted answer

Try using ElementsService:
$entry = craft()->elements->getElementByUri( 'blog/article1' );

> **Comments:**
> **username_0**: 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!  
> **username_1**: No worries – it's often like that with Craft, no? :)  

---

