I have had a look at the source code of Wordpress, as well as php.net for a possible answer. However, I was not able to get close to finding it.

For the source code, I was assuming I would find it in one of the many files I checked in the wp-includes folder. However, there are way! to many files to look through.

What I want to know if how does Wordpress manage to get Theme/Plugin/Template name and other information from the headers of the specific files? If it were XML data or PHP variables, it would make sense. However the data is places in PHP Comments! How does one read comments?

Theme Name: Twenty Sixteen
Theme URI: https://wordpress.org/themes/twentysixteen/
Author: the WordPress team
Author URI: https://wordpress.org/
Description: Twenty Sixteen is a modernized take on an ever-popular WordPress layout Version: 1.2
License: GNU General Public License v2 or later
Text Domain: twentysixteen

One question here on StackOverflow suggested the use of getDocComment() however now another question comes to me mind, first, how do we only get a specific block of comments?

Even if we manage to get all the content of the comment, how do we manage to get the "Theme Name" into a variable and so on?

2 Answers 2


The function is called get_file_data, it uses a regular expression to parse the text and find headers.


My previous answer was very close -- but then I realized get_plugin_data() only works in wp-admin. So I experimented, and this will give you everything you need:

    $my_theme = wp_get_theme( 'twentyfifteen' );
    if ( $my_theme->exists() )

        echo '<p>Theme Author: ' . $my_theme['Author']. '</p>';

    if ( ! function_exists( 'get_plugins' ) ) {
        require_once ABSPATH . 'wp-admin/includes/plugin.php';
    $pluginfile = ABSPATH . 'wp-content/plugins/give/give.php';
    $plugindata = get_plugin_data( $pluginfile );

    echo '<p>Plugin Name: ' . $plugindata['Name']. '</p>';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.