admin管理员组

文章数量:1429044

Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 5 years ago.

Improve this question

I would like to know how to remove the site logo only for a single post in WordPress.

Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 5 years ago.

Improve this question

I would like to know how to remove the site logo only for a single post in WordPress.

Share Improve this question edited May 9, 2019 at 10:31 norman.lol 3,2413 gold badges30 silver badges35 bronze badges asked May 9, 2019 at 6:43 Coves84Coves84 1 5
  • 1 Welcome to WP SE. please elaborate more information with your question. what you've done so far etc... – Vishwa Commented May 9, 2019 at 6:52
  • I was hoping there was a quick css code fix like some other posts ;) – Coves84 Commented May 9, 2019 at 6:57
  • there could be, or not. can't answer without understanding question right? – Vishwa Commented May 9, 2019 at 6:58
  • Yes, on that post your body tag has class postid-513 so you could write a style for that that hides some or all of the header, e.g. .postid-513 header { display: none; }, or hide div.branding-wrapper, or something else. However I'd probably modify my template's header.php to not emit the logo based on some property of the post that you can then set, e.g. a flag in postmeta. – Rup Commented May 9, 2019 at 7:24
  • Thank you that worked fine for me. .postid-513 header { display: none; } – Coves84 Commented May 9, 2019 at 9:28
Add a comment  | 

1 Answer 1

Reset to default 1

You can surround your logo part with IF and check if current post is not that one that should not have the logo.

It looks like you're talking about a custom post type, so you should use is_single() conditional tag with the ID or SLUG of no-logo-post as a parameter.

if ( ! is_single(513) ) // or slug: is_single('your_post_slug')
{
    // display logo here 
}

You can also use a custom action hook in the header to display the logo, and place the HTML code of the logo in the function. The header file will remain clean if you have more exceptions, additionally, the use of filter will allow e.g. plugins to change the visibility of the logo. It would look something like this:

header.php

<!-- here logo will be displayed -->
<?php do_action( 'se337467_header_logo' ); ?>

functions.php

add_action( 'se337467_header_logo', 'se337467_display_logo' );
function se337467_display_logo()
{
    $show_logo = true;
    if ( ! is_single(513) )
        $show_logo = false;
    //
    // allow to override visibility
    $show_logo = apply_filter( 'se337467_show_logo', $show_logo);
    if ( $show_logo !== TRUE )
       return;
    ?>
    <!-- HTML with logo -->
    <?php
}

// 
// change visibility through the filter
add_filter( 'se337467_show_logo',  'my_other_function' );
function my_other_function( $show_logo )
{
    // you can show or hide logo
    return $show_logo;
}

本文标签: Remove the logo on specific post