Scriptbaker
SCRIPTBAKERAI & Software Engineering
Magento

Get Magento Website Meta Data and Config Values

Learn how to get Magento 2 website metadata and configuration values using <code>ScopeConfigInterface</code>, store scopes, and Magento APIs. This guide covers base URLs, store information, product and category SEO metadata, CLI configuration commands, best practices, and common FAQs.

· 5 min read · By Tahir Yasin

Magento 2 and Adobe Commerce provide several ways to retrieve website metadata and configuration values programmatically. This is useful when developing custom modules, themes, SEO features, integrations, and dynamic storefront components.

In Magento 2, configuration values are identified by a configuration path such as web/unsecure/base_url or general/store_information/name. Configuration can be available at different scopes, including global, website, and store view.

What You Can Retrieve

Depending on your requirement, you may need to retrieve:

  • Store name
  • Store email address
  • Base URL
  • Secure HTTPS URL
  • Default country and locale
  • Currency settings
  • SEO configuration
  • Product meta title and meta description
  • Custom extension configuration values
  • Website-specific or store-view-specific settings

Adobe Commerce uses a cascading configuration model of global, website, store, and store-view scopes. Therefore, the value returned can depend on the current store context.

Get Magento Configuration Values Using ScopeConfigInterface

The recommended Magento 2 approach for reading configuration values from PHP is to use Magento\Framework\App\Config\ScopeConfigInterface.

<?php
namespace Vendor\Module\Model;
use Magento\Framework\App\Config\ScopeConfigInterface;
class Config{
    private ScopeConfigInterface $scopeConfig;
    public function __construct(
        ScopeConfigInterface $scopeConfig
    ) {
        $this->scopeConfig = $scopeConfig;
    }
    public function getStoreName(): ?string
    {
        return $this->scopeConfig->getValue(
            'general/store_information/name'
        );
    }
}

The configuration path is the key used to identify a particular setting. Magento's CLI documentation also uses these paths when displaying or setting configuration values.

Get the Magento Store Name

The store name can be retrieved from the general/store_information/name configuration path.

$storeName = $this->scopeConfig->getValue(    'general/store_information/name');

This can be useful when generating dynamic page content, emails, structured data, or custom frontend output.

Get the Magento Base URL

You can retrieve the configured base URL through the configuration system.

$baseUrl = $this->scopeConfig->getValue(    'web/unsecure/base_url');

For HTTPS configuration, you can read the secure base URL:

$secureBaseUrl = $this->scopeConfig->getValue(    'web/secure/base_url');

Magento's configuration CLI documentation uses web/unsecure/base_url as an example configuration path.

Get a Store-Specific Configuration Value

When working with multiple websites or store views, it is important to specify the correct scope when necessary.

use Magento\Store\Model\ScopeInterface;
$value = $this->scopeConfig->getValue(
    'general/store_information/name',
    ScopeInterface::SCOPE_STORE
);

Magento supports a hierarchy in which configuration can apply globally or be overridden at website and store-view levels. Store views are commonly used for localized storefronts and language-specific content.

Get a Configuration Value for a Specific Store View

If you need a value for a particular store view rather than the current context, you can provide the store ID.

$value = $this->scopeConfig->getValue(    'general/store_information/name',    \Magento\Store\Model\ScopeInterface::SCOPE_STORE,    $storeId);

This approach is particularly useful for cron jobs, integrations, APIs, and backend processes where there may not be an active storefront store view.

Get Product Meta Title and Meta Description

Product SEO data is different from system configuration. Product metadata is stored as product attributes, including meta_title and meta_description. Adobe Commerce documents these fields as product SEO attributes.

You can retrieve these values from a product model:

$metaTitle = $product->getMetaTitle();$metaDescription = $product->getMetaDescription();

For example:

$product = $this->productRepository->getById($productId);
$metaTitle = $product->getMetaTitle();
$metaDescription = $product->getMetaDescription();

Magento also supports automatically generated metadata based on configured templates and product values.

Get Category Meta Data

Category SEO information is also stored as category data rather than as a general system configuration value.

$metaTitle = $category->getMetaTitle();$metaDescription = $category->getMetaDescription();

This distinction is important: use ScopeConfigInterface for system configuration, while product and category repositories/models should be used to access entity-specific SEO attributes.

Get Store Information

Magento store information such as the store name can be retrieved through configuration values.

$storeName = $this->scopeConfig->getValue(
    'general/store_information/name',
    \Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
$phone = $this->scopeConfig->getValue(
    'general/store_information/phone',
    \Magento\Store\Model\ScopeInterface::SCOPE_STORE
);

The exact availability and scope of a setting depends on how that configuration field is defined.

Check Configuration Values From the Magento CLI

Magento provides the bin/magento config:show command for viewing saved configuration values.

bin/magento config:show general/store_information/name

You can also display all saved configuration values:

bin/magento config:show

For a specific scope, Magento supports the --scope and --scope-code options.

bin/magento config:show \--scope=websites \--scope-code=base \web/unsecure/base_url

Adobe's current CLI documentation confirms that config:show can display configuration values and that encrypted settings are masked rather than exposed as plaintext.

Where Magento Configuration Values Are Stored

Magento configuration can come from several sources. Default module configuration is commonly defined in config.xml, while Admin changes are stored in the database. Deployment configuration can also be stored in app/etc/config.php and environment-specific or sensitive settings in app/etc/env.php.

  • etc/config.xml — default module configuration
  • app/etc/config.php — shared deployment configuration
  • app/etc/env.php — environment-specific and sensitive configuration
  • core_config_data — database-backed configuration values

Because configuration can be overridden at different levels, directly reading the database is generally not the right way to retrieve a configuration value from application code. Magento's configuration APIs handle the configuration hierarchy for you.

Magento Configuration Scope Matters

One of the most common sources of unexpected values is using the wrong scope.

For example, a store may have multiple store views with different configuration values. Magento's scope hierarchy allows configuration to cascade from global settings down to website and store-view settings.

When retrieving a value, consider whether the setting should be read at:

  • Global/default scope
  • Website scope
  • Store view scope

Do Not Expose Sensitive Configuration Values

Be careful when displaying configuration values in frontend responses, logs, APIs, or debugging output.

Sensitive configuration can include credentials, private keys, API secrets, and other environment-specific values. Adobe Commerce provides separate handling for sensitive configuration and masks encrypted values when using configuration display commands.

Never print sensitive configuration values directly into HTML or expose them through a public API simply for debugging purposes.

Best Practices for Magento Configuration Retrieval

  • Use ScopeConfigInterface instead of directly querying the configuration database.
  • Use the correct scope when working with multiple websites or store views.
  • Use product or category APIs for entity-specific SEO metadata.
  • Avoid hard-coding URLs when Magento configuration can provide them dynamically.
  • Do not expose sensitive configuration values in frontend code or logs.
  • Use dependency injection instead of creating Magento objects directly with the Object Manager.
  • Use the Magento CLI to inspect configuration during development and troubleshooting.
  • Keep environment-specific and sensitive configuration out of source control where appropriate.

Magento Metadata vs Configuration Values

Data Typical Magento Source Example
Store name System configuration general/store_information/name
Base URL System configuration web/unsecure/base_url
Product meta title Product attribute meta_title
Product meta description Product attribute meta_description
Category meta title Category data meta_title

Adobe Commerce's current documentation confirms that product metadata fields such as meta title and meta description are product attributes, while system configuration is accessed through configuration paths and scopes.

Conclusion

Getting Magento website metadata and configuration values is straightforward when the correct Magento API is used. For system settings, ScopeConfigInterface is the standard approach. For product and category SEO information, use the corresponding product or category data.

Understanding Magento's configuration scope is especially important for stores with multiple websites or store views. Using the correct scope prevents unexpected values and makes custom Magento modules more reliable.

Frequently Asked Questions

1. How do I get a Magento 2 configuration value?

Inject Magento\Framework\App\Config\ScopeConfigInterface into your class and call getValue() with the configuration path.

$value = $this->scopeConfig->getValue(    'general/store_information/name');

2. How do I get the Magento base URL?

You can retrieve the configured base URL with the configuration path:

$baseUrl = $this->scopeConfig->getValue(    'web/unsecure/base_url');

3. How do I get a product's meta title in Magento 2?

Product metadata is stored with the product. You can retrieve it using the product object:

$metaTitle = $product->getMetaTitle();

Magento documents meta_title and meta_description as product SEO fields.

4. How do I get a product's meta description?

Use the product's getMetaDescription() method:

$metaDescription = $product->getMetaDescription();

5. What is ScopeConfigInterface used for?

ScopeConfigInterface provides access to Magento system configuration values while respecting Magento's configuration architecture and scope.

6. Why am I getting a different configuration value than expected?

The most common reason is configuration scope. A value may be defined globally but overridden for a website or store view. Check the active scope and use the appropriate scope code when retrieving the value.

7. Can I check Magento configuration from the command line?

Yes. Magento provides bin/magento config:show for displaying saved configuration values.

bin/magento config:show general/store_information/name

Adobe Commerce documents config:show as the CLI command for displaying configuration values.

8. Should I query the core_config_data table directly?

For application code, it is generally better to use Magento's configuration APIs rather than directly querying core_config_data. Magento's configuration system handles defaults, overrides, and scopes for you.

9. Are Magento product meta fields the same as configuration values?

No. Product meta title and meta description are product attributes, while settings such as store name and base URL are system configuration values. They should therefore be retrieved through different Magento APIs.

10. Is it safe to print all Magento configuration values for debugging?

No. Some configuration values can contain sensitive information. Avoid exposing configuration data in public responses, browser output, or logs. Magento also masks encrypted values when displaying configuration through the CLI.

Last updated:

Work with Scriptbaker

Let's talk about your project

Whether you're extending an existing platform, modernising legacy code, or planning something new, our engineers can help. Tell us what you're working on and we'll explore a practical technical solution together.