Traduce CPT

Home » Snippets » Traduce CPT
0

Created with:

Visibility: 

public

Creator: rhs@mediastuff.com.ar

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project
					<?php
/**
 * Plugin Name: WP Plugin
 * Description: A plugin for displaying translated CPT titles.
 * Version: 1.0
 * Author: WP Turbo
 * Author URI: https://wpturbo.dev
 * Text Domain: wpturbo
 */

// Hook into the post title display
add_filter('register_post_type_args', 'wpturbo_translate_cpt_labels', 10, 2);

function wpturbo_translate_cpt_labels($args, $post_type) {
    // Get the current language
    $current_language = pll_current_language();
    
    // Check if it is the desired CPT
    if ($post_type === 'producto') {
        // Check if the current language is English
        if ($current_language === 'en') {
            // Translate the labels to English
            $args['labels']['name'] = 'Products';
            $args['labels']['singular_name'] = 'Product';
        } elseif ($current_language === 'pt') {
            // Translate the labels to Portuguese
            $args['labels']['name'] = 'Produtos';
            $args['labels']['singular_name'] = 'Produto';
        }
    } elseif ($post_type === 'test-de-calidad') {
        // Check if the current language is English
        if ($current_language === 'en') {
            // Translate the labels to English
            $args['labels']['name'] = 'Quality Tests';
            $args['labels']['singular_name'] = 'Quality Test';
        } elseif ($current_language === 'pt') {
            // Translate the labels to Portuguese
            $args['labels']['name'] = 'Testes de Qualidade';
            $args['labels']['singular_name'] = 'Teste de Qualidade';
        }
    } elseif ($post_type === 'industria') {
        // Check if the current language is English
        if ($current_language === 'en') {
            // Translate the labels to English
            $args['labels']['name'] = 'Market We Serve';
            $args['labels']['singular_name'] = 'Market';
        } elseif ($current_language === 'pt') {
            // Translate the labels to Portuguese
            $args['labels']['name'] = 'Forneces para seguintes indústrias';
            $args['labels']['singular_name'] = 'Indústria';
        }
    }

    // Return the modified arguments
    return $args;
}
				

Register an account to save your snippets or go Pro to get more features.