Enable "featured image" on specific WordPress pages

2

I used the following command to enable "featured images" in the posts of my WordPress site:

// HABILITANDO IMAGENS DESTACADAS EM POSTS
add_theme_support('post-thumbnails', array('post'));

How do I enable this feature on some site-specific pages? I do not want to enable on all pages. Just for example, on the "About" page and the "Contact" page.

    
asked by anonymous 28.02.2018 / 15:56

1 answer

0

This refinement can only be done with CSS or JavaScript.

The action is only applied on pages wp-admin/post.php and wp-admin/post-new.php . The global $current_screen has the Post Type information being displayed.
And the global $post has the information about the current post where we check the permalink, eg http://site.com/contato .

add_action( 'admin_footer-post.php', 'metabox_sopt_279492' );
add_action( 'admin_footer-post-new.php', 'metabox_sopt_279492' );

function metabox_sopt_279492() {
    global $current_screen, $post;
    if ( 'page' != $current_screen->id ) 
        return; 

    $checkpages = array( 'sobre', 'contato' );
    if( in_array( $post->post_name, $checkpages ) )
        return;
    ?>
    <script type="text/javascript">
        jQuery(document).ready( function($) {   
            $('#postimagediv').remove(); 
        });
    </script>
    <?php
}
    
05.04.2018 / 05:02