Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-06T17:37:48.400Z
Answers.Text: What about siteName?
Answers.UserDisplayName: Cat Named Dog
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-07T06:13:28.010Z
Answers.Text: @good_afternoon I just updated my answer to include that.
Answers.UserDisplayName: Simon Kuran
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-26T22:13:56.050Z
Answers.LastActivityDate: 2020-12-07T06:13:03.867Z
Answers.LastEditDate: 2020-12-07T06:13:03.867Z
Answers.UserDisplayName: Simon Kuran
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-01T19:54:21.720Z
Answers.Text: 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?
Answers.UserDisplayName: Zack Brady
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-02T00:38:57.550Z
Answers.Text: Shouldn't. Can you add your `craft/config/general.php` contents to the original question?
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-01T19:46:51.830Z
Answers.LastActivityDate: 2015-10-02T00:38:24.243Z
Answers.LastEditDate: 2015-10-02T00:38:24.243Z
Answers.UserDisplayName: Brad Bell
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-01T22:40:42.180Z
Answers.LastActivityDate: 2015-10-01T22:40:42.180Z
Answers.UserDisplayName: Brandon Kelly
Body: <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>
  
Tags: <plugin-development><globals>
Title: How to retrieve Site Url and Site Name in Plugin
ThreadText: # 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?  
  
  ---
  
  