Warning: call_user_func_array() expects parameter 1 to be a valid callback, function '_wp_footnotes_kses_init' not found or invalid function name in /home/clients/d53f41ae2001453fbced93bf985d42c7/web/wp-includes/class-wp-hook.php on line 307

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function '_wp_footnotes_kses_init' not found or invalid function name in /home/clients/d53f41ae2001453fbced93bf985d42c7/web/wp-includes/class-wp-hook.php on line 307
Fonctions WordPress – Yvonnou Théo }
Yvonnou Théo

Ingénieur d'étude et développement

Infotel

Développeur Java

Yvonnou Théo

Ingénieur d'étude et développement

Infotel

Développeur Java

Articles

Fonctions WordPress

10 juillet 2019 Français, Rappel, Wordpress
Fonctions WordPress

Voici quelques fonctions à mettre dans le fichier functions.php de votre thème enfant.

Faire une redirection :

// Redirection
add_action('template_redirect','my_template_redirect');
function my_template_redirect() {
    $redirect_to = false;
    list($url_path,$params) = explode('?',$_SERVER['REQUEST_URI']);
    switch ($url_path) {
        case '/mon/url/source/':
            $redirect_to = '/mon/url/destination/';
            break;
    }
    if ($redirect_to) {
        wp_safe_redirect($redirect_to,301);
        exit();
    }
}

Traduire des textes :

add_filter('gettext', 'wpm_traduction');
add_filter('ngettext', 'wpm_traduction');
function wpm_traduction($texte) {
    $texte = str_ireplace('Hello', 'Bonjour', $texte);
    $texte = str_ireplace('Bye', 'Au revoir', $texte);
    // Si je veux traduire "Comment" 
    // Sans obtenir des Commentairesaires là où il est déjà traduit
    $text = preg_replace('/\bComment\b/', 'Commentaires', $text);
    return $texte;
}

Taggs: