How to get plugin data programatically – get_plugin_data

A really great and clever little function in WordPress I only just recently discovered, is the get_plugin_data function. This function will return the data you enter into the header of your WordPress plugin, so you can use a clever template structure for when you create new plugins.

The plugin will return an array of the following information:

‘Name’ – Name of the plugin, must be unique.
‘Title’ – Title of the plugin and the link to the plugin’s web site.
‘Description’ – Description of what the plugin does and/or notes
from the author.
‘Author’ – The author’s name
‘AuthorURI’ – The authors web site address.
‘Version’ – The plugin version number.
‘PluginURI’ – Plugin web site address.
‘TextDomain’ – Plugin’s text domain for localization.
‘DomainPath’ – Plugin’s relative directory path to .mo files.

So, if your plugin follows the proper structure expected of a WordPress plugin, you can dynamically get the information about your plugin. For instance, I use it to display the current version in the header of the Settings page in my plugins.

Previously, I could easily forget to change the version number all places where I use it, but now it is no problem.

Example:

$seoboosterpropluginfo=get_plugin_data(__FILE__);
$version=$seoboosterpropluginfo['Version'];

Echo "I'm running v. $version";

Leave a Comment





Cleverplugins.com Newsletter

Articles about how to improve your WordPress website, how to get more traffic and most importantly more customers.

Subscribe

Something went wrong. Please check your entries and try again.