使用媒体名称重命名帖子标题 - Wordpress

时间:2017-10-11 19:12:51

标签: wordpress file media custom-post-type

我有一个带有海关帖子和元标箱的wordpress网站。 其中一个管理一些图片,我想强制帖子的标题。 它应与上传媒体的名称相同。

有可能吗?如何 ?

感谢' s

2 个答案:

答案 0 :(得分:1)

Manipulate the post title with a filter.

function change_post_title( $title, $id = null ) {

    if ( is_single() ) {
        $title = 'new title';
    }

    return $title;
}

add_filter( 'the_title', 'change_post_title', 10, 2 );

答案 1 :(得分:0)

感谢大家的帮助。

我使用过滤器,但是这个:

function modify_post_title($data){
      if($data['post_type'] == 'fcfm_photos' && isset($_POST['image'])) { 
         $data['post_title'] = substr($_POST['image'], -(strpos(strrev($_POST['image']),'/')));  
      }
      return $data;
    }
add_filter( 'wp_insert_post_data' , 'modify_post_title' , '99', 1 );

当我保存帖子时,帖子标题会自动更改。这就是我想要的。