#SysAdmin #NetAdmin

WordPress – Personnalisation

W

Mise à jour article

  • 25/02/2024 : Restructuration de l’article
  • 03/05/2020 : Limiter les révisions

Functions.php

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 l’exécution du PHP dans un 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);

WPCONFIG.PHP

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

define( 'WP_POST_REVISIONS', 5 );

Code PHP

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; ?>
par Nathan
#SysAdmin #NetAdmin