<p>In Craft 3 you can do this:</p>
<pre><code>use craft\helpers\UrlHelper;
UrlHelper::siteUrl();

Craft::$app-&gt;sites-&gt;currentSite-&gt;name;
</code></pre>

CC BY-SA 4.0
2020-12-06T17:37:48.400Z
What about siteName?
Cat Named Dog
CC BY-SA 4.0
2020-12-07T06:13:28.010Z
@good_afternoon I just updated my answer to include that.
Simon Kuran
CC BY-SA 4.0
2018-10-26T22:13:56.050Z
2020-12-07T06:13:03.867Z
2020-12-07T06:13:03.867Z
Simon Kuran
<p>What you've done should work fine for actual <a href="http://buildwithcraft.com/docs/multi-environment-configs#environment-specific-variables" rel="nofollow">environment variables</a>, but both <a href="http://buildwithcraft.com/docs/config-settings#siteUrl" rel="nofollow">siteUrl</a> and <a href="http://buildwithcraft.com/docs/config-settings#siteName" rel="nofollow">siteName</a> are proper <a href="http://buildwithcraft.com/docs/config-settings" rel="nofollow">config settings</a> that you can access via <code>craft()-&gt;config-&gt;get('siteUrl')</code> and <code>craft()-&gt;config-&gt;get('siteName')</code>.</p>

CC BY-SA 3.0
2015-10-01T19:54:21.720Z
I am still have issues retrieving the values in this way. Note: I am accessing them via an Event, specifically when an entry is saved. Would that have an impact on this?
Zack Brady
CC BY-SA 3.0
2015-10-02T00:38:57.550Z
Shouldn't. Can you add your `craft/config/general.php` contents to the original question?
Brad Bell
CC BY-SA 3.0
2015-10-01T19:46:51.830Z
2015-10-02T00:38:24.243Z
2015-10-02T00:38:24.243Z
Brad Bell
<p>You can get them via <a href="http://buildwithcraft.com/classreference/etc/behaviors/AppBehavior#getSiteUrl-detail" rel="noreferrer">craft()->getSiteUrl()</a> and <a href="http://buildwithcraft.com/classreference/etc/behaviors/AppBehavior#getSiteName-detail" rel="noreferrer">craft()->getSiteName()</a>.</p>

CC BY-SA 3.0
2015-10-01T22:40:42.180Z
2015-10-01T22:40:42.180Z
Brandon Kelly
<p>I'm having an exceedingly difficult time trying to retrieve the Site URL and Name in a custom plugin I am developing.</p>

<p>My research has led me to believe this would work:</p>

<pre><code>$envVar = craft()-&gt;config-&gt;get('environmentVariables');
$siteUrl = $envVar['siteUrl'];
$siteName = $envVar['siteName'];
</code></pre>

<p>But in practice this hasn't worked. Does anyone know the correct way?</p>

<plugin-development><globals>
How to retrieve Site Url and Site Name in Plugin
# How to retrieve Site Url and Site Name in Plugin

(Asked by: username_0 on 2015-10-01)

I'm having an exceedingly difficult time trying to retrieve the Site URL and Name in a custom plugin I am developing.
My research has led me to believe this would work:
$envVar = craft()->config->get('environmentVariables');
$siteUrl = $envVar['siteUrl'];
$siteName = $envVar['siteName'];

But in practice this hasn't worked. Does anyone know the correct way?

**Tags:** plugin-development, globals


---

## 3 answers

### Answer by username_4 on 2015-10-01. Score: 6 | Accepted answer

You can get them via [craft()->getSiteUrl()](http://buildwithcraft.com/classreference/etc/behaviors/AppBehavior#getSiteUrl-detail) and [craft()->getSiteName()](http://buildwithcraft.com/classreference/etc/behaviors/AppBehavior#getSiteName-detail).


---

### Answer by username_1 on 2018-10-26. Score: 14

In Craft 3 you can do this:
use craft\helpers\UrlHelper;
UrlHelper::siteUrl();

Craft::$app->sites->currentSite->name;

> **Comments:**
> **username_2**: What about siteName?  
> **username_1**: @good_afternoon I just updated my answer to include that.  

---

### Answer by username_3 on 2015-10-01. Score: 1

What you've done should work fine for actual [environment variables](http://buildwithcraft.com/docs/multi-environment-configs#environment-specific-variables), but both [siteUrl](http://buildwithcraft.com/docs/config-settings#siteUrl) and [siteName](http://buildwithcraft.com/docs/config-settings#siteName) are proper [config settings](http://buildwithcraft.com/docs/config-settings) that you can access via `craft()->config->get('siteUrl')` and `craft()->config->get('siteName')`.

> **Comments:**
> **username_0**: I am still have issues retrieving the values in this way. Note: I am accessing them via an Event, specifically when an entry is saved. Would that have an impact on this?  
> **username_3**: Shouldn't. Can you add your `craft/config/general.php` contents to the original question?  

---

