【问题标题】:Change Wordpress Post Title Placeholder更改 Wordpress 帖子标题占位符
【发布时间】:2014-12-03 04:25:08
【问题描述】:

我正在创建自定义帖子类型,并希望在“创建新帖子”部分的标题字段中操作占位符文本。

要求:
- 它只能针对一种特定的帖子类型,而不是针对所有帖子。
- 不能反映帖子类型的名称,必须是完全自定义的文字。
- 它不必在 wordpress 管理部分进行编辑,自定义文本可以放在 functions.php 文件中的函数内。

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    您也可以将其用于多种帖子类型

    add_filter('enter_title_here', 'my_title_place_holder' , 20 , 2 );
        function my_title_place_holder($title , $post){
            // For Activities
        if( $post->post_type == 'activities' ){
            $my_title = "Activity Name";
                    return $my_title;
        }
            // For Instructors
        elseif( $post->post_type == 'instructors' ){
                $my_title = "Instructor Name";
                    return $my_title;
        }
    
        return $title;
            }
    

    【讨论】:

      【解决方案2】:

      你可以把这个sn-p放在你的functions.php中

      function change_default_title( $title ){
      
      $screen = get_current_screen();
      
      if ( 'your_custom_post_type' == $screen->post_type ){
      $title = 'Your custom placeholder text';
      }
      
      return $title;
      }
      
      add_filter( 'enter_title_here', 'change_default_title' );
      

      这应该改变标题。

      发现于:https://gist.github.com/FStop/3094617

      【讨论】:

        猜你喜欢
        • 2015-07-26
        • 2022-09-23
        • 1970-01-01
        • 2011-07-11
        • 1970-01-01
        • 1970-01-01
        • 2014-03-04
        • 1970-01-01
        • 2018-01-11
        相关资源
        最近更新 更多