How to Disable Title on Posts, Pages, or Other Post Types?

How to Disable Title on Posts, Pages, or Other Post Types?

The title is the name of your post, page, or other post types you might have on your website. The title appears in the frontend and can be disabled with Astra Settings or with the custom code

Method 1 – Page/Post Astra Settings

Page/Post meta settings or Astra Settings are available for each individual post or page. Thus, using the Astra Settings you can decide for each post, page, or post type to disable the Title where needed. You can find these settings by accessing your post/page backend editor (e.g Dashboard > Posts > 「Edit」) – check the menu on the right side and scroll down to 「Astra Settings」:

If you wish to apply this setting to a larger number of pages or posts, then editing every page and updating the above setting can be time-consuming. In this case, you can use Astra Bulk Edit plugin. This will allow editing the above settings on multiple pages.

Method 2 – Custom Code

You can also do this using a custom code. This can be a great solution if you want to disable titles on all posts, pages, or other post types.

You can add the following custom code to the functions.php file of your Child Theme:

/**
* Disable title on all post types.
*/
function your_prefix_post_title() {
$post_types = array('page','post');

// bail early if the current post type if not the one we want to customize.
if ( ! in_array( get_post_type(), $post_types ) ) { return; }

// Disable title.
add_filter( 'astra_the_title_enabled', '__return_false' );
}
add_action( 'wp', 'your_prefix_post_title' );

If you don』t have your Child Theme installed, please check this article on how to do it. 

If you are not sure how to add this code, please check this article.

This code will remove titles on all of your pages and posts. You can apply this code only to pages, posts, any of your other post types, or all of them by modifying the bolded part of the code above. Here are the examples how this should look like:

To remove titles on all your posts only:

$post_types = array('post');

To remove titles on all your pages only:

$post_types = array('page');

To remove titles on all pages, posts and example custom post type. This is the example which you can use to add any other post types you want the above code to be applied:

$post_types = array('page','post','custom-type-1');

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注