Get Parent Theme Author Name

I want to to get the Author name of the Parent theme.

I can get the theme name using wp_get_theme() to get the theme object of the current (child) theme. From this I can get the parent theme name.

Next I think I need to get the object of the parent theme, but unsure how best to approach this. Here is my code so far:

$style_parent_theme = wp_get_theme();
$style_parent_theme_dir = $style_parent_theme-get( 'Template' );
$style_parent_theme_name = wp_get_theme($parent_theme_dir);
$style_parent_theme_author = $style_parent_theme_name-get( 'Author' );

if ($style_parent_theme_author == "WooThemes") {

Topic wp-get-theme parent-theme child-theme Wordpress

Category Web


I was searching for getting the name of the parent theme and stumbled over this post.

I think the best solution is not mentioned here:

wp_get_theme()->parent()->get( 'Author' );

or what I needed:

wp_get_theme()->parent()->get( 'Name' )

simple function

function show_theme_author(){

    $theme = wp_get_theme();

    return $theme->get('Author');

}

Thanks for all the help which pointed me in the right direction. In the end I used the following:

$style_parent_theme = wp_get_theme(get_template());
$style_parent_theme_author = $style_parent_theme->get( 'Author' );

I use get_template() to recover the folder name of the parent theme.

wp_get_theme then get's the theme object.

Once we have that we can manipulate the object to get the author name.


You can get this value about the child theme. At first get your child theme date. The simplest way is the function wp_get_theme(), see codex for the parameters and more information. You get a object with all relevant information about the current theme. In step two check, if is a child theme and then get his parent information, like the follow source.

// Current WP_Theme object.
// Get this data via hook or class WP_Theme
// As wrapper, simple to sue is the function wp_get_theme()
$theme_data    = wp_get_theme();
$is_child      = $this->is_child( $theme_data );

if ( $is_child ) {
    $parent_name = $theme_data->parent()->Name;
}

The method is_child is simple:

function is_child( $theme_data ) {
    // For limitation of empty() write in var
    $parent = $theme_data->parent();
    if ( ! empty( $parent ) ) {
        return TRUE;
    }
    return FALSE;
}

Line 3 of your code reads:

$style_parent_theme_name = wp_get_theme($parent_theme_dir);

it should be:

$style_parent_theme_name = wp_get_theme($style_parent_theme_dir);

otherwise the code is correct.


This works for me.

  <?php
  $my_theme = wp_get_theme('parentThemeName');
  echo $my_theme->get( 'Author' );
  ?>

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.