Support

Account

Home Forums ACF PRO Delete WP Title and use ACF Title Reply To: Delete WP Title and use ACF Title

  • This take a couple of steps, first hiding the title WP title field. I see that you’re also not using the WP editor so that makes it a bit easier

    
    add_action('admin_head', 'hide_wp_title_input');
    function hide_wp_title_input() {
      $screen = get_current_screen();
      if ($screen->id != 'your-custom-post-type') {
        return;
      }
      ?>
        <style type="text/css">
          #post-body-content {
            display: none;
          }
        </style>
      <?php 
    }
    

    next, update the post to use the custom title field for the post title

    
    // you'll want to rename the function
    add_action('acf/save_post', 'save_post_type_post'), 20); // fires after ACF
    function save_post_type_post($post_id) {
      $post_type = get_post_type($post_id);
      if ($post_type != 'your-custom-post_type') {
        return;
      }
      $post_title = get_field('your_custom_field', $post_id);
      $post_name = sanitize_title($post_title);
      $post = array(
        'ID' => $post_id,
        'post_name' => $post_name,
        'post_title' => $post_title
      );
      wp_update_post($post);
    }