You can use is_admin()
to check if the request is done being inside /wp-admin.
function suppressed_title($title, $id) {
if (is_admin()) {
return $title;
}
if (get_page_template_slug() === 'custom-template.php' && get_post_type($id) === 'page') {
$title="";
}
return $title;
}
add_filter('the_title', 'suppressed_title', 10, 2);
I changed your code to use triple equals ===
over ==
as this is usually considered best practice. (See this StackOverflow answer for more info.)
I want to hide the page titles that use a custom page template
Technically, you’re not hiding the title right now, but displaying an empty title. This might have effects on the styling anyway. In my opinion a cleaner solution would be not to display the title at all at these pages. But this is highly dependent on which theme you are using.
Related Posts:
- Inconsistent temporary 404s on whole install | PHP error with post-template.php
- Query menu_order custom post types
- Search that will look in custom field, post title and post content
- Load custom posts with same tag as page
- using the_permalink to echo an href into a
- Date archives for custom post type
- If featured image doesn’t exist, show post content
- How can I add dropdown widget/box to admin post page?
- Meta Query “IN” doesn’t work with ACF checkbox filter
- How do I redirect all 404 errors of a specific post type to another URL?
- Using ‘strtotime’ function to convert a custom-meta-box to a date-stamp
- Get custom post type REST API not working
- How to save the checked boxes?
- How to get only one category of custom post type?
- Error after deleting Custom Post Type with a function (no trash used)
- Get all taxonomies for all post types
- Append taxonomy terms as class names in markup?
- Change message given when deleting post from custom post type
- wordpress custom post type remove duplicate menu item
- Using WPAlchemy metabox values in another metabox
- List terms from Custom Taxonomy
- Display custom field of specific post where post title matches variable
- How to count custom post types with conditional operators
- GravityForm: Populate Dropdown with custom post type [closed]
- How to output wordpress custom tags separated by comma?
- Show Different Header on a Specific Post ID
- Admin notice not displaying
- Dynamic page outside WordPress
- Using wordpress template tags within an array
- Getting the URL of the parent page
- Custom query to filter posts that have current post as a taxonomy [closed]
- Changing number of posts per page on CPT-archive.php, have tried 20-30 code chunks so far
- Custom Post Type Loop throws 500 error when used in widget
- Received nothing after executing AJAX post function
- If post has custom field then display css-class
- Custom Tag Description unable to display just below and outside of the Loop
- I need to add endpoint for wordpress categories
- Can one create multiple Custom Post Types with a for loop?
- Categorize custom post type
- Hide a widget inside a div on specific type of post
- How to import a custom MySQL DB table into a WordPress custom post type
- Breaking up CPT output into two columns
- Function causing the loop display posting more (empty)
- Foreach inside shortcode not working as planned
- Displaying custom field according to date
- Add additional field to custom post_type
- Set featured image to archive.php
- how to echo meta tag in header using php
- Get term name without a foreach loop
- PHP question: how to combine syntax?
- Add first letter of titles to array, then compare arrays
- custom post for slider
- Using wp_query to modify the loop in index.php for a CPT
- Get custom post type categories to show up in menus
- How exclude or skip post type with get_next_post_link
- How do I add custom HTML to the content of an archive page’s posts?
- widget_posts_args not using the number of posts in widget
- Create short URL with auto 301 redirect
- Is it possible to use array_walk() to append terms to an array of posts?
- get_post_types() can’t get some of my post type
- Creating shortcode id for custom post types
- Importing JSON feed giving Notice: Array to string conversion error
- Different column width in 2 rows with bootstrap and custom post types-different classes needed
- Menu’s breaking, now showing all page links on site
- Create an user checklist system for a course plateform using ACF Pro and ACF Extended
- Page that lists publications by classifying them by taxonomy
- count & sum the value of custom field of the author post in dynamic posts
- On saving Post My permalink is updated and category is removed automatically which cause the 404
- Query custom post type that has a serialized relational advanced custom field value
- Pagination not working in custom post type. Help
- How to add specific terms in a custom post type?
- Sending current featured image to email
- Plugin Development using classes – Public & Private Callbacks
- Limit custom post type to the authors only on front-end!
- WP_Query – How To Query Only Custom Posts With No Children of Their Own?
- programmatically generated custom post type is created more than once
- How to use posts as tabs in a custom page?
- Accessing download link from the loop with WP Download Manager Pro
- Create posts inside CPT post
- Taxonomies are not showing in the category dropdown
- Combine multiple separate lists into one
- News post with multiple permalinks? When opened from different page
- Custom Taxonomy – fields
- WordPress trying to query two custom types to get child from the parent
- Wrap each child and it’s grandchildren separately
- Print post category name from a custom post type wordpress
- CPT post doesnt shows tags and category on backend admin page
- How to make sure, that only the selected post is changing?
- Create 2-layered dropdown menus for custom taxonomy and custom post type
- Why isn’t my custom post type using the corresponding custom post template?
- Get month and day from a Date Picker custom field
- Show Custom Post Type taxonomy term that matches custom field
- Order by custom field attribute
- Select Menu for Custom post Type does not save
- is_singular won’t call my functions?
- Cant we use a PHP file directly like myhome.com/some.php?
- Code in custom widget queries all posts, when it should only query the current post
- Inserting two categories
- Comments are not working on Custom Post Type
- Add Category names to post lists of custom post type