用媒体名称重命名 post 标题 - Wordpress

Rename the post title with media name - Wordpress

我有一个带有自定义 posts 和 metas 框的 wordpress 网站。 其中一个管理一些图片,我想强制post的标题。 应与上传的媒体名称相同

可能吗?如何 ?

谢谢

使用过滤器处理 post 标题。

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

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

    return $title;
}

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

感谢大家的帮助。

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

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 );

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