8.5.x bootstrap.inc drupal_get_path($type, $name)
8.0.x bootstrap.inc drupal_get_path($type, $name)
8.1.x bootstrap.inc drupal_get_path($type, $name)
8.2.x bootstrap.inc drupal_get_path($type, $name)
8.3.x bootstrap.inc drupal_get_path($type, $name)
8.4.x bootstrap.inc drupal_get_path($type, $name)
8.6.x bootstrap.inc drupal_get_path($type, $name)
4.6.x common.inc drupal_get_path($type, $name)
4.7.x common.inc drupal_get_path($type, $name)
5.x common.inc drupal_get_path($type, $name)
6.x common.inc drupal_get_path($type, $name)
7.x common.inc drupal_get_path($type, $name)

Returns the path to a system item (module, theme, etc.).


$type: The type of the item; one of 'core', 'profile', 'module', 'theme', or 'theme_engine'.

$name: The name of the item for which the path is requested. Ignored for $type 'core'.

Return value

The path to the requested item or an empty string if the item is not found.

88 calls to drupal_get_path()
AggregatorTestBase::getAtomSample in core/modules/aggregator/src/Tests/AggregatorTestBase.php
Returns a example Atom feed.
AggregatorTestBase::getHtmlEntitiesSample in core/modules/aggregator/src/Tests/AggregatorTestBase.php
Returns a example feed.
AggregatorTestBase::getRSS091Sample in core/modules/aggregator/src/Tests/AggregatorTestBase.php
Returns a example RSS091 feed.
CKEditor::buildContentsCssJSSetting in core/modules/ckeditor/src/Plugin/Editor/CKEditor.php
Builds the "contentsCss" configuration part of the CKEditor JS settings.
CKEditorLoadingTest::testLoading in core/modules/ckeditor/src/Tests/CKEditorLoadingTest.php
Tests loading of CKEditor CSS, JS and JS settings.

... See full list


core/includes/bootstrap.inc, line 258
Functions that need to be loaded on every Drupal request.


function drupal_get_path($type, $name) {
  return dirname(drupal_get_filename($type, $name));


arunkumark’s picture

To accessing any files like style CSS file, Javascript files or any images from a File module can be used like this.

$imgLink = drupal_get_path('module', 'MODULE_NAME') . '/image/user.png';
print $imgLink; // Image path

Folder structure be like,
-- MODULE_NAME.module
-- MODULE_NAME.info.yml
-- image
-- user.png

ssibal’s picture

This is a global function. Any services that can do this for you?

gabesullice’s picture

If you're using drupal_get_path in Drupal 8 and are just using it to retrieve the path of your module, try:

$module_handler = Drupal::service('module_handler');
$path = $module_handler->getModule('your_module')->getPath();

As always, if you're in the context of a class, you should inject the 'module_handler' service rather than calling Drupal::service statically.

leymannx’s picture

$handler = \Drupal::service('theme_handler');
$path    = $handler->getTheme('YOUR_THEME')->getPath();