How to set/get base_path in D8? How do I get the base_path in Drupal 8? When I use the base_path() function it always returns just the /. I know in Drupal 7 you could set the base_url in the settings.php file, but how do I set it in Drupal 8?

I'm trying to create an absolute url for social media sharing.
You're looking for $base_url global:

global $base_url;


If you want to have this in a preprocess function, you'd have to call it within that function; for example:

function YOUR_THEME_preprocess_whatever(&amp;$variables) {
  global $base_url;
  // Now you can use it.
  $variables['base_url'] = $base_url;
}