【问题标题】:Empty post title Wordpress空帖子标题 Wordpress
【发布时间】:2019-02-04 22:09:02
【问题描述】:

有没有办法检查帖子标题是否为空,然后如果帖子标题为空,则自动将该帖子设置为草稿或隐藏在前端?我知道有一个插件https://wordpress.org/plugins/post-title-validation/ 但对我来说不是选择。 有什么方法可以实现吗?

喜欢:

【问题讨论】:

    标签: html wordpress wordpress-theming


    【解决方案1】:

    wp_insert_post_data 过滤器可以做到这一点:

    add_filter( 'wp_insert_post_data' , 'filter_post_data' , '99', 2 );
    function filter_post_data( $data , $postarr ) {
        // Change post status if empty post title
        if( empty($data['post_title']) ) {
          $data['post_status'] = 'draft';
        }
        return $data;
    }
    

    【讨论】:

    • 非常感谢 :-)
    【解决方案2】:

    我发现输入 </> 也可以。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-04
      • 1970-01-01
      • 2011-12-19
      • 1970-01-01
      • 1970-01-01
      • 2012-09-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多