#SysAdmin #NetAdmin

Astuces WordPress

A

Maj 03/05/2020: limiter les révisions

Dernièrement j’ai dû faire pas mal de modifications sur un site que je gère et qui tourne sous WordPress, je vous partage les astuces / personnalisations que j’ai pu mettre en place.

Les morceaux de code ci-dessous sont à placer majoritairement dans le fichier “functions.php” de votre thème sauf cas contraire il y aura une précision.

Supprimer certains menus du tableau de bord

add_action('admin_menu', 'remove_menu_pages');
function remove_menu_pages() {
if (!(current_user_can('administrator'))) {
	remove_menu_page( 'wpcf7' );
	remove_menu_page('tools.php');
	remove_menu_page('edit-comments.php');
	}
}

Remplacer texte “admin. site”

add_filter( 'register' , 'xbs_change_site_admin_text');
function xbs_change_site_admin_text( $link ){
    if ( is_user_logged_in() ) {
        $link = '<li><a href="' . admin_url() . '">' . __('Tableau de gestion') . '</a></li>';
    }
    return $link;
}

Autoriser execution php dans widget texte

function execute_php_text_widget($html){
     if(strpos($html,"<"."?php")!==false){
          ob_start();
          eval("?".">".$html);
          $html=ob_get_contents();
          ob_end_clean();
     }
     return $html;
}
add_filter('widget_text','execute_php_text_widget',100);

Modification email et nom par défaut

function csnd_sender_email( $original_email_address ) {
    return 'votre_adresse_email';
}
function csnd_sender_name( $original_email_from ) {
    return 'nom_du_site';
}
add_filter( 'wp_mail_from', 'csnd_sender_email' );
add_filter( 'wp_mail_from_name', 'csnd_sender_name' );

Récupérer le nom du template en cours d’utilisation pour la page, à placer dans la boucle du footer par exemple

<?php global $template; echo basename($template); ?>

Récupérer les articles avec les métas

<?php
$args = array( 'numberposts' => 5 );
$lastposts = get_posts( $args );
foreach($lastposts as $post) : setup_postdata($post); ?>
	<hr style="margin-bottom: 5px;"/>
	<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
	<?php the_excerpt(); ?>
	<div class="meta-article">
	<p style="text-align: right;"><i class="icon-calendar"></i> Publié le <?php the_date('d F Y'); ?> par <?php the_author_posts_link(); ?> dans la catégorie <?php the_category( '/ '); ?></p>
	</div>
<?php endforeach; ?>

Limiter les révisions des pages et articles, à placer dans le fichier wp-config.php

define( 'WP_POST_REVISIONS', 5 );

 

Ne pas hésiter à me demander si vous avez besoin d’explications

par Nathan
#SysAdmin #NetAdmin