LoginSignup
4
4

More than 5 years have passed since last update.

WordPressの投稿一覧画面に最終更新者追加

Last updated at Posted at 2018-02-06

やりたいこと

Wordpressに作成者はあるが更新者がない。
設定にないのでプラグインを用いて追加する。

完成イメージ

wp01.png

手順

1.WordPressフォルダにある【\wp-content】に適当なフォルダを作成
2.以下のplugin.phpファイルを作成
3.WordPressでプラグイン->インストール済みプラグイン->最終更新者追加に進み有効化にする
4.投稿一覧で最終更新者が追加されているのを確認

plugin.php
<?php
/*
Plugin Name: 最終更新者追加
Author: h2
Version: 1.0.0
Author URI:
*/

add_filter( 'manage_posts_columns', 'itsg_add_custom_column' );
add_action( 'manage_posts_custom_column' , 'itsg_add_custom_column_data', 10, 2 );

function itsg_add_custom_column( $columns ) {
    $columns['modified'] = '最終更新者';
    return $columns;
}

function itsg_add_custom_column_data( $column, $post_id ) {
    switch ( $column ) {
        case 'modified' :
            $post = get_post( $post_id );
         // ここで表示項目調整
        echo the_modified_author(); 
        break;
    }
}

プラグインの内容

WordPressの機能は既存に用意されているフック(add_filterやadd_action)して機能追加する。
以下のサイトを参考に今回、投稿(post)の一覧画面にフックして機能追加を行った。

参考サイト

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4