Désactiver les plugins wordpress inutiles de la page d’accueil


2 Méthodes possibles


1- Méthode simple, utiliser un plugin :

WordPress Assets manager, dequeue scripts, dequeue styles

Ou la version plus complète :

Clearfy

 


2- Méthode manuelle:

 

I- Cibler les plugins chargés sur votre page d’accueil

 

Pour ce faire ajoutez ce code à votre fichier function.php (/wp-content/theme/[votre_theme])

Il va afficher tous les plugins chargés avec leur nom dans le pied de page. Il faut être connecté pour le voir.

// list loaded assets by our theme and plugins so we know what we're dealing with. This is viewed by admin users only.
add_action('wp_print_footer_scripts', 'wra_list_assets', 900000);
function wra_list_assets(){
if ( !is_admin() ){
return;
}
echo '<h2>List of all scripts loaded on this particular page.</h2>';
echo '<p>This can differ from page to page depending of what is loaded in that particular page.</p>';
// Print all loaded Scripts (JS)
global $wp_scripts;
wra_print_assets($wp_scripts);
echo '<h2>List of all css styles loaded on this particular page.</h2>';
echo '<p>This can differ from page to page depending of what is loaded in that particular page.</p>';
// Print all loaded Styles (CSS)
global $wp_styles;
wra_print_assets($wp_styles);
}
// both $wp_styles and $wp_scripts are objects and store loaded CSS/JS files in $wp_styles->queue
function wra_print_assets($wp_asset){
$nb_of_asset = 0;
foreach( $wp_asset->queue as $asset ) :
$nb_of_asset ++;
$asset_obj = $wp_asset->registered[$asset];
wra_asset_template($asset_obj, $nb_of_asset);
endforeach;
}
function wra_asset_template($asset_obj, $nb_of_asset){
if( is_object( $asset_obj ) ){
echo '<div class="wra_asset" style="padding: 2rem; font-size: 0.8rem; border-bottom: 1px solid #ccc;">';
echo '<div class="wra_asset_nb"><span style="width: 150px; display: inline-block">Number:</span>';
echo $nb_of_asset . '</div>';
echo '<div class="wra_asset_handle"><span style="width: 150px; display: inline-block">Handle:</span>';
echo $asset_obj->handle . '</div>';
echo '<div class="wra_asset_src"><span style="width: 150px; display: inline-block">Source:</span>';
echo $asset_obj->src . '</div>';
echo '<div class="wra_asset_deps"><span style="width: 150px; display: inline-block">Dependencies:</span>';
foreach( $asset_obj->deps as $deps){
echo $deps . ' / ';
}
echo '</div>';
echo '<div class="wra_asset_ver"><span style="width: 150px; display: inline-block">Version:</span>';
echo $asset_obj->ver . '</div>';
echo '</div>';
}
}
view raw wp-list-scripts.php hosted with ❤ by GitHub

code from here

 

II- Enlever les plugins voulus de la page d’accueil

 

On utilise encore une fois function.php.

Voila la méthode :

//Supprimer les scripts et css de la page d'accueil
function remove_scripts_home() {
if (is_home()){
wp_dequeue_script( 'script_handle' );
wp_deregister_script( 'script_handle' );
}
}
add_action('wp_print_scripts', 'remove_scripts_home', 100);
function remove_styles_home() {
if (is_home()){
wp_dequeue_style( 'style_handle' );
wp_deregister_style( 'style_handle' );
}
}
add_action('wp_print_styles', 'remove_styles_home', 100);</pre>
Remplacez script_handle et style_handle par le nom (handle) du script/css trouvé grâce à l'étape 1.
Pour ce site j'utilise cette configuration :
<pre class="lang:default decode:true">//remove home scripts and styles
function remove_scripts_home() {
if (is_home()){
wp_dequeue_script( 'crayon_js' );
wp_deregister_script( 'crayon_js' );
wp_dequeue_script( 'bp-confirm' );
wp_deregister_script( 'bp-confirm' );
wp_dequeue_script( 'bp-legacy-js' );
wp_deregister_script( 'bp-legacy-js' );
wp_dequeue_script( 'jquery-form' );
wp_deregister_script( 'jquery-form' );
wp_dequeue_script( 'frontjs' );
wp_deregister_script( 'frontjs' );
wp_dequeue_script( 'jquery-choosen' );
wp_deregister_script( 'jquery-choosen' );
wp_dequeue_script( 'dwqa_simplemde' );
wp_deregister_script( 'dwqa_simplemde' );
wp_dequeue_script( 'wp-embed' );
wp_deregister_script( 'wp-embed' );
wp_dequeue_script( 'modernizr' );
wp_deregister_script( 'modernizr' );
wp_dequeue_script( 'tc-fancybox' );
wp_deregister_script( 'tc-fancybox' );
wp_dequeue_script( 'jquery-ui-core' );
wp_deregister_script( 'jquery-ui-core' );
}
}
add_action('wp_print_scripts', 'remove_scripts_home', 100);
function remove_styles_home() {
if (is_home()){
wp_dequeue_style( 'crayon' );
wp_deregister_style( 'crayon' );
wp_dequeue_style( 'crayon-theme-github' );
wp_deregister_style( 'crayon-theme-github' );
wp_dequeue_style( 'crayon-font-monaco' );
wp_deregister_style( 'crayon-font-monaco' );
wp_dequeue_style( 'bp-admin-bar' );
wp_deregister_style( 'bp-admin-bar' );
wp_dequeue_style( 'bp-legacy-css' );
wp_deregister_style( 'bp-legacy-css' );
wp_dequeue_style( 'wpdm-front' );
wp_deregister_style( 'wpdm-front' );
wp_dequeue_style( 'dwqa-style' );
wp_deregister_style( 'dwqa-style' );
wp_dequeue_style( 'dwqa-style-rtl' );
wp_deregister_style( 'dwqa-style-rtl' );
wp_dequeue_style( 'dwqa_simplemde' );
wp_deregister_style( 'dwqa_simplemde' );
wp_dequeue_style( 'dwqa_leaderboard' );
wp_deregister_style( 'dwqa_leaderboard' );
wp_dequeue_style( 'customizr-style' );
wp_deregister_style( 'customizr-style' );
wp_dequeue_style( 'fancyboxcss' );
wp_deregister_style( 'fancyboxcss' );
}
}
add_action('wp_print_styles', 'remove_styles_home', 100);

Pour enlever des plugins de post/articles il suffit de rajouter/remplacer

if (is_home()){ par if (is_single()){

Laissez un commentaire

Votre adresse de messagerie ne sera pas publiée.

Search
Generic filters
Exact matches only
Filter by Custom Post Type