Don’t hack your WordPress core. It’s overriden after every upgrade (plugins do exist for some reason).
You can solve your problem in this way:
1) Open your single.php
.
2) Define
<?php
function hideAdminBar ($post_id)
{
if (get_post_type ($post_id) == 'post')
{
add_filter ('show_admin_bar', '__return_false');
/* For removing the top blank space. */
echo '<style type="text/css" media="screen">
html { margin-top: 0px !important; }
* html body { margin-top: 0px !important; }
</style>';
}
}
?>
3) Inside The Loop, call this function right after the while
condition. Like this:
<?php while ( have_posts() ) : the_post();?>
<?php hideAdminBar (get_the_ID ()); ?>
/* etc. */
<?php endwhile; ?>
Hope this solves your issue.
Related Posts:
- Change order of an item under “New” on the admin bar
- Setting proper query for multiple custom admin filters
- Default post tab showing twice in admin bar
- Custom post type, taxonomy and admin bar
- custom filtering admin columns
- Admin menu link with variable
- Use template_include with custom post types
- Combining Multiple Taxonomies in one URL
- Creating custom user roles
- Not Able to Insert Taxonomy Term Using wp_insert_post()
- Listing posts with wp-cli
- Is there a way to keep a custom menu expanded when editing a custom post type?
- Restrict taxonomy dropdown to post type
- Allow User to Edit Page Based on their Email
- Regex problem in an add_rewrite_rule
- Conditional two level dropdown filter for custom post type
- Sort Posts Best Practice
- Get all children of custom post type using get_pages
- using custom taxonomies on non wp table?
- Custom permalink – append taxonomy name and term name at the end of permalink
- Admin Column Text Positioning
- wp_get_nav_menu_items wp-admin/customize.php problem
- Assign Taxonomy Based on Custom Field Value
- How to fetch custom post by Author?
- Custom Taxonomy Creates Unwanted Integer Terms on Post Save
- Assigning the same custom meta box to multiple post types
- Blog page showing same content as homepage
- Where to store custom tagging data associated with a custom post type
- Modifying Custom Post Type after registration (will it affect content?)
- How to quickly reorder posts in the admin panel that will persist for the wp-api
- Podcast Guest List
- Remove Slug From Custom Post Type URL?
- Custom post type and permalink issue
- Custom post type not displaying all entries
- Show custom post type filtered by category
- Displaying Page as Custom Post type landing Page
- Listing tags from a custom post type
- create a subcatagory for a custom post type and out put url as posttype/subcategory/item
- How do I display the taxonomy term alongside the post type post title?
- Disable user from updating certain posts
- Custom Post, set object Taxonomy terms in plugin
- Rewrite Endpoints and CPTs – How to use in a plugin
- Review site custom post type structure
- How to remove Trash link from custom post type
- Can I display custom post types in home.php or need page template?
- Relationship between set rewrite flag in register_post_type and add_rewrite_rule
- Display custom post using ID
- Loop through custom posts by taxonomy and display the titles in a list, it is repeating 8 times
- retrieve permalinks of posts inside custom post type by using post ID
- Can I change my post type to anything and my site still work?
- page not found for single-type.php file
- echo selected value from dropdown
- How to change base in tag URL for custom post type, to not use “Custom Structure” set in Permalinks setting?
- Combine multiple CPT names to create valid permalinks
- Get parent category(taxonomy) ID from single template of a custom post type
- Default Category Page not showing custom post type which has taxonomy category
- Capabilities not working with custom post type
- Custom post types sorting admin columns nothing found
- How can I see a list of products that I have set to outofstock through a custom field check box?
- Different structure/content for posts from a custom post type
- Add term for custom taxonomy from front end
- delete duplicate meta_value with same post_id
- CPT archive page – show one post from each taxonomy term
- Subpages Permalinks Issues
- Custom post-type custom query – show all posts
- Display custom post type from template
- How do I make a request in my browser to search the CPT taxonomy?
- Change Text in Admin Panel
- Limiting actions only to edit.php page for specific custom post type
- Adding a location field to buddypress activity
- How to Grab Anime info using Jikan API and fill the value in Metabox
- How to generate auto shortcode for custom post type same as Elementor Template?
- Custom meta fields not showing up in WP_Response Object via custom endpoint
- Query a Custom Post Type using SELECT that has ACF fields to compare dates
- I want to create a metabox under custom taxonomy
- How to output and alert message when updating a post
- Getting 404 on child page with pre_get_posts() on custom posts
- Custom post type and custom page name
- Post list displaying wrong in Chrome and Firefox
- Return Additional Fields When Selecting Max Value of Meta Key from wp-postmeta table
- Custom Post Type with Custom Taxonomy in Bootstrap 4 Accordion
- Hierarchical Custom Post Type Walker?
- Changing menu label to post name for custom post type
- Featured image in custom post is being disabled
- Remove Custom Capability
- CPT and metabox: create multi checkbox by using array?
- Get posts in same category not working
- Is it possible to add query parameters on the archive page?
- Permalinks when using Custom Post Type with static page for archive
- Custom sortable pages on custom post type
- How do I add custom fields to posts without having to manually add everytime I post?
- Query Only Show Text on Posts With Certain Taxonomy Tag
- Remove ?preview=true from the address of custom post types
- Use only selected regular categories for a Custom post form
- Custom Post Type to Upload Images
- How to make a template for a specific post of a custom post type?
- Hierarchical Custom Post Types
- ACF select box css color change
- Menu Structure and URL structure, with Pages and Post-Type-Posts
- Two pagination in one page without AJAX