Skip to content

🌐 Leggi in Italiano

Reading the data in the header of a plugin's main file

A closer look at get_plugin_data(), a very handy function for managing updates to your plugins' assets through versioning.

Alessandro Manias Alessandro Manias Published on · Updated on · 1 min read
Cover image: Reading the data in the header of a plugin's main file

We have already covered how to access the data written in a theme's main style.css file.

This data is very useful for versioning the files you enqueue in your plugin, and it lets you manage the plugin's own version and the other information shown in the plugins screen.

Contents

Which functions let us read the plugin's metadata?

We discussed metadata in a previous article, along with the generic get_file_data function.

To read the data in the header of a plugin's main file you can use the get_plugin_data() function.

get_plugin_data()

As an example, imagine you have the following folder in your plugins directory:

  • your-plugin
    • your-plugin.php

The header of your-plugin.php contains the following comment:

<?php
/**
 * Plugin Name: Your plugin name
 * Description: Description of your plugin.
 * Version: 0.0.1
 *
 */

The function is called like this:

<?php
// ...
$plugin_data = get_plugin_data( __FILE__ );

echo $plugin_data['Version'];

// prints
// 0.0.1

get_plugin_data takes the path of the plugin's main file, reads the comment at the top and produces an associative array like the following.

<?php
// example of the resulting array.
array(
 'Plugin Name' => 'Your plugin name',
 'Description' => 'Description of your plugin.',
 'Version' => '0.0.1',
);

If you want to dig deeper, the main source of information on WordPress development is the WordPress developer site.

© 2026 Wordpress e PHP. Statically generated with SvelteKit.