Temps de chargement de WP

Améliorez le temps de chargement du CMS WordPress


Codes types pour les transients

Code 1 : [pastacode lang=”php” manual=”function%20seomix_transient()%7B%0A%09%2F%2FQuel%20est%20le%20nom%20du%20transient%20%3F%0A%09%24nomtransient%20%3D%20’tototransient’%3B%0A%0A%09%2F%2FLe%20transient%20est-il%20inexistant%20ou%20expir%C3%A9%20%3F%0A%09if%20(%20false%20%3D%3D%3D%20(%20%24transient%20%3D%20get_transient(%20%24nomtransient%20)%20)%20)%20%7B%0A%0A%09%09%2F%2FSi%20oui%2C%20je%20fais%20appel%20%C3%A0%20n%E2%80%99importe%20quelle%20fonction%20pour%20donner%20une%20valeur%20au%20futur%20transient.%20Dans%20mon%20exemple%2C%20ce%20sera%20ma%20fonction%20toto%20().%0A%09%09%24value%20%3D%20toto()%3B%0A%0A%09%09%2F%2FJe%20mets%20%C3%A0%20jour%20la%20valeur%20du%20transient%20avec%20%24value%2C%20et%20j%E2%80%99indique%20%C3%A0%20WordPress%20une%20dur%C3%A9e%20d%E2%80%99expiration%20de%2060%20secondes.%0A%09%09set_transient(%24nomtransient%2C%20%24value%2C%2060)%3B%0A%0A%09%09%2F%2FJe%20mets%20%C3%A0%20jour%20la%20valeur%20de%20ma%20variable%20%24transient%2C%20car%20%C3%A0%20ce%20stade%20elle%20est%20encore%20%C3%A9gale%20%C3%A0%20false%20.%0A%09%09%24transient%20%3D%20get_transient(%20%24nomtransient%20)%0A%09%7D%0A%0A%09%2F%2FJe%20renvoie%20la%20valeur%20du%20transient%20mis%20%C3%A0%20jour.%0A%09return%20%24transient%3B%0A%7D” message=”Exemple de code pour un transient dans WordPress” highlight=”” provider=”manual”/] Code 2 : [pastacode lang=”php” manual=”%2F%2F%20Cr%C3%A9ation%20de%20l%E2%80%99action%20qui%20va%20d%C3%A9clencher%20la%20suppression%20des%20transients%0Afunction%20seomix_content_transients_opti()%20%7B%0A%09seomix_action_delete_transient()%3B%0A%7D%0A%0A%2F%2F%20Activation%20de%20l%E2%80%99action%20en%20m%C3%AAme%20temps%20que%20wp_scheduled_delete%0A%2F%2F%20La%20variable%20EMPTY_TRASH_DAYS%20doit%20%C3%AAtre%20d%C3%A9finie%20dans%20le%20fichier%20wp%20-%20c%20onfig.%0A%2F%2F%20Par%20exemple%20%3A%20define(‘EMPTY_TRASH_DAYS’%2C%203%20)%3B%0Aadd_action(%20’wp_scheduled_delete’%2C%20’seomix_content_transients_opti’%20)%3B%0A%0A%2F%2F%20Fonction%20de%20suppression%20des%20transients%0Afunction%20seomix_action_delete_transient()%20%7B%0A%09%2F%2F%20Si%20WordPress%20ne%20fait%20pas%20appel%20%C3%A0%20un%20cache%20externe%0A%09global%20%24_wp_using_ext_object_cache%3B%0A%09%0A%09if%20(%20!%24_wp_using_ext_object_cache%20)%20%7B%0A%09%09%2F%2F%20On%20r%C3%A9cup%C3%A8re%20la%20globale%20du%20site%0A%09%09global%20%24wpdb%3B%0A%09%0A%09%09%2F%2F%20On%20r%C3%A9cup%C3%A8re%20l%E2%80%99heure%20actuelle%0A%09%09%24time%20%3D%20time()%3B%0A%09%0A%09%09%2F%2F%20On%20r%C3%A9cup%C3%A8re%20tous%20les%20transients%20trop%20vieux%0A%09%09%24sql%20%3D%20%22SELECT%20option_name%20FROM%20%24wpdb-%3Eoptions%20WHERE%20option_name%20LIKE%20’_transient_timeout%25’%20AND%20option_value%20%3C%20%24time%22%3B%0A%09%0A%09%09%2F%2F%20On%20les%20r%C3%A9cup%C3%A8re%20proprement%0A%09%09%24mestransients%20%3D%20%24wpdb-%3Eget_col(%20%24sql%20)%3B%0A%09%0A%09%09%2F%2F%20Pour%20chacun%20d%E2%80%99entre%20eux%2C%20on%20les%20supprime%0A%09%09foreach(%20%24mestransients%20as%20%24transient%20)%20%7B%0A%09%09%09%24deletion%20%3D%20delete_transient(%20str_replace(%20’_transient_timeout_’%2C%20”%2C%20%24transient%20)%20)%3B%0A%09%09%7D%0A%09%0A%09%09%2F%2F%20On%20optimise%20la%20base%20de%20donn%C3%A9es%20apr%C3%A8s%20les%20suppressions%0A%09%09%24wpdb-%3Equery(‘OPTIMIZE%20TABLE%20’%20.%20%24wpdb-%3Eoptions)%3B%0A%09%7D%0A%7D” message=”Nettoyage automatique des transients” highlight=”” provider=”manual”/] Un article traite ce sujet en profondeur sur SeoMix : Transient et WordPress : comment les utiliser ?

Changer la compression des images de WordPress

Code type : [pastacode lang=”php” message=”” highlight=”” provider=”manual” manual=”add_filter(‘jpeg_quality’%2C%20function(%24arg)%7Breturn%2080%3B%7D)%3B”/] Code pour PHP inférieur à 5.3 : [pastacode lang=”php” message=”” highlight=”” provider=”manual” manual=”add_filter(%20’jpeg_quality’%2C%20create_function(%20”%2C%20’return%2080%3B’%20)%20)%3B”/]

Améliorer les performances avec WP-config (ch.15.)

Code 1 : [pastacode lang=”php” message=”Réduire le nombre de révisions de chaque article” highlight=”” provider=”manual” manual=”define(‘WP_POST_REVISIONS’%2C%205)%3B”/] Code 2 : [pastacode lang=”php” message=”Désactiver les révisions” highlight=”” provider=”manual” manual=”define(‘WP_POST_REVISIONS’%2Cfalse)%3B”/] Code 3 : [pastacode lang=”php” message=”Régler le temps entre chaque sauvegarde automatique” highlight=”” provider=”manual” manual=”define(‘AUTOSAVE_INTERVAL’%2C%20300)%3B”/] Code 4 [pastacode lang=”php” message=”Ne pas envoyer de cookies aux sous-domaines” highlight=”” provider=”manual” […]

Améliorer la vitesse d’un thème WordPress (CSS, HTML, etc.)

Pour apprendre à améliorer la vitesse de WordPress, suivez le lien contenu dans cet article.

© 2013-2022 Optimiser son référencement WordPress, le livre - Par Daniel Roch


Theme by Anders NorenHaut de page ↑