Search code examples
wordpressapirestwordpress-themingwordpress-rest-api

How to get WordPress theme name by custom URL


I'm trying to get WordPress theme name using API. I have tried this code but I want the same result using custom url:

function theme_list_function(){
    // Get a list of themes
    $list = wp_get_themes();
    // Return the value
    var_dump($list);
}

This code will return current WordPress theme list. I want theme list form a URL like xyz.com


Solution

  • I have achieved this using this code:

    $target_site    = ""; // put your wordpress url here
    $src            = file_get_contents( $target_site );
    preg_match("/\<link rel='stylesheet'.*href='(.*?style\.css.*?)'.*\>/i", $src, $matches );
    
    if( $matches ) {
        $style_href     = trim( $matches[1] );
        $style_src      = file_get_contents( $style_href );
        preg_match( "/\Theme Name:(.*?)\n/i", $style_src, $theme_name );
    
        $theme_name = str_replace(' ', '', $theme_name[1]);
    
        var_dump( $theme_name );
    
    }