function active( $plugin ) {
    $network_active = false;
    if ( is_multisite() ) {
        $plugins = get_site_option( 'active_sitewide_plugins' );
        if ( isset( $plugins[$plugin] ) ) {
            $network_active = true;
        }
    }
    return in_array( $plugin, get_option( 'active_plugins' ) ) || $network_active;
}
if ( active( 'wordpress-seo/wp-seo.php' ) {
I used this function to detect yoast seo and it wiorks but if the yoast seo is renamed then it wont work so i need a backup