Ask your WordPress questions! Pay money and get answers fast! (more info)

Remove featured image from Standard Post Type PHP WordPress

  • SOLVED

Please let me know what changes I need to make to this default blog template in order to remove featured image from the top of the page:


<?php
/**
* The default template for displaying content
*
* Used for both single and index/archive/search.
*
* @package WordPress
* @subpackage ninetheme_cobian
* @since ninetheme_cobian 1.0
*/
?>
<!-- Start article 1 -->
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="row">
<div class="col-md-2 col-sm-2">
<div class="meta-column">
<span>
<i class="fa fa-calendar"></i><br />
<a href="<?php get_permalink(); ?>"><?php the_time('d.m.Y') ?></a>
</span>
<span>
<i class="fa fa-comment"></i><br />
<a href="<?php get_comments_link(); ?>"><?php get_comments_number(); ?></a>
</span>
</div>
</div>
<?php if ( has_post_thumbnail() ) : ?>
<!-- Article Image -->
<?php
$ninetheme_cobian_single_thumb = get_post_thumbnail_id();
$ninetheme_cobian_single_img_url = wp_get_attachment_url( $ninetheme_cobian_single_thumb,'full' ); //get full URL to image (use "large" or "medium" if the images too big)


$thumb = get_post_thumbnail_id();
$img_url = wp_get_attachment_url( $thumb,'full' ); //get full URL to image (use "large" or "medium" if the images too big)
$image = aq_resize( $img_url, 262, 250, true ); //resize & crop the image
?>


<?php if ( is_single() ) : ?>
<div class="col-md-10 col-sm-10 marginbot40">
<img src="<?php echo esc_url($ninetheme_cobian_single_img_url); ?>" class="img-responsive" alt="" />
</div>
<?php else :?>
<div class="col-md-4 col-sm-5">
<img src="<?php echo esc_url($image); ?>"class="img-responsive" alt="Exemple">
<?php ?>
</div>
<?php endif;?>
<?php endif; ?>

<?php if ( is_single() ) :?>
<?php the_title( '<div class="col-md-12 col-sm-12"><h5>', '</h5>' ); ?>
<?php else : ?>
<?php the_title( sprintf( '<div class="col-md-6 col-sm-6"><h5 class="entry-title all-caps"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h5>' );?>
<?php endif; ?>

<ul class="meta-post">
<li><a href="#"><span class="fa fa-user"></span><?php the_author(); ?></a></li>
<li><a href="#"><span class="fa fa-thumb-tack"></span><?php the_category(', '); ?></a></li>
<?php the_tags( '<li><span class="fa fa-tags"></span>', ',', '</li> '); ?>
</ul>

<?php
/* translators: %s: Name of current post */
the_content( sprintf(
esc_html__( 'Continue reading %s', 'ninetheme_cobian' ),
the_title( '<span class="screen-reader-text">', '</span>', false )
) );
?>

<?php if ( ! is_single() ) : ?>
<a class="btn btn-primary" href="<?php echo get_permalink(); ?>" role="button"><?php esc_html_e( 'Read more', 'ninetheme_cobian' ); ?></a>
<?php endif; // is_single() ?>

<div id="share-buttons">
<a href="http://www.facebook.com/sharer.php?u=<?php echo get_permalink(); ?>" target="_blank"><i class="fa fa-facebook"></i></a>
<a href="http://twitter.com/share?url=<?php echo get_permalink(); ?>s" target="_blank"><i class="fa fa-twitter"></i></a>
<a href="https://plus.google.com/share?url=<?php echo get_permalink(); ?>" target="_blank"><i class="fa fa-google-plus"></i></a>
<a href="http://www.digg.com/submit?url=<?php echo get_permalink(); ?>" target="_blank"><i class="fa fa-digg"></i></a>
<a href="http://reddit.com/submit?url=<?php echo get_permalink(); ?>" target="_blank"><i class="fa fa-reddit"></i></a>
<a href="http://www.linkedin.com/shareArticle?mini=true&url=<?php echo get_permalink(); ?>" target="_blank"><i class="fa fa-linkedin"></i></a>
<a href="http://www.stumbleupon.com/submit?url=<?php echo get_permalink(); ?>" target="_blank"><i class="fa fa-stumbleupon"></i></a>
<a href="mailto:?Subject=Simple Share Buttons&Body=I%20saw%20this%20and%20thought%20of%20you!%20 <?php echo get_template_directory_uri(); ?>"><i class="fa fa-envelope-o"></i></a>
</div>

</div>
</div>
</article><!-- #post-## -->

Answers (5)

2016-10-02

Rempty answers:

Remove

<div class="col-md-10 col-sm-10 marginbot40">
<img src="<?php echo esc_url($ninetheme_cobian_single_img_url); ?>" class="img-responsive" alt="" />
</div>

2016-10-02

Fahad Murtaza answers:

Remove this code block


<!-- Article Image -->

<?php

$ninetheme_cobian_single_thumb = get_post_thumbnail_id();

$ninetheme_cobian_single_img_url = wp_get_attachment_url( $ninetheme_cobian_single_thumb,'full' ); //get full URL to image (use "large" or "medium" if the images too big)





$thumb = get_post_thumbnail_id();

$img_url = wp_get_attachment_url( $thumb,'full' ); //get full URL to image (use "large" or "medium" if the images too big)

$image = aq_resize( $img_url, 262, 250, true ); //resize & crop the image

?>





<?php if ( is_single() ) : ?>

<div class="col-md-10 col-sm-10 marginbot40">

<img src="<?php echo esc_url($ninetheme_cobian_single_img_url); ?>" class="img-responsive" alt="" />

</div>

<?php else :?>

<div class="col-md-4 col-sm-5">

<img src="<?php echo esc_url($image); ?>"class="img-responsive" alt="Exemple">

<?php ?>

</div>

<?php endif;?>

<?php endif; ?>






scaban84 comments:

I still want a featured image but only for thumbnails on a preview grid.
This seems like it will keep a thumbnail from being generated no?

2016-10-03

Krishna Tiwari answers:

Hi,
<em>If you want to removed featured images options from admin, then add following code:</em>
<strong>wp-admin:</strong>
add_action( 'init', 'my_init' );
function my_init() {
remove_post_type_support( 'post', 'thumbnail' );
}


<strong>For Front end:</strong>
<em>Please remove:</em>
<?php if ( has_post_thumbnail() ) : ?>

<!-- Article Image -->

<?php

$ninetheme_cobian_single_thumb = get_post_thumbnail_id();

$ninetheme_cobian_single_img_url = wp_get_attachment_url( $ninetheme_cobian_single_thumb,'full' ); //get full URL to image (use "large" or "medium" if the images too big)





$thumb = get_post_thumbnail_id();

$img_url = wp_get_attachment_url( $thumb,'full' ); //get full URL to image (use "large" or "medium" if the images too big)

$image = aq_resize( $img_url, 262, 250, true ); //resize & crop the image

?>





<?php if ( is_single() ) : ?>

<div class="col-md-10 col-sm-10 marginbot40">

<img src="<?php echo esc_url($ninetheme_cobian_single_img_url); ?>" class="img-responsive" alt="" />

</div>

<?php else :?>

<div class="col-md-4 col-sm-5">

<img src="<?php echo esc_url($image); ?>"class="img-responsive" alt="Exemple">

<?php ?>

</div>

<?php endif;?>

<?php endif; ?>


2016-10-03

Arnav Joy answers:

can you show us your site please ?

2016-10-03

Ryan S answers:

Do something between this line of code


<?php if ( is_single() ) : ?>
<div class="col-md-10 col-sm-10 marginbot40">

<img src="<?php echo esc_url($ninetheme_cobian_single_img_url); ?>" class="img-responsive" alt="" />

</div>

<?php else :?>

<div class="col-md-4 col-sm-5">

<img src="<?php echo esc_url($image); ?>"class="img-responsive" alt="Exemple">

<?php ?>

</div>

<?php endif;?>


First solution:

<?php if ( is_single() ) : ?>
<!--Standard wp post-type is obviously post and page only -->
<?php if ( 'post' == get_post_type() ) : ?>
<div class="col-md-10 col-sm-10 marginbot40">
<img src="<?php echo esc_url($ninetheme_cobian_single_img_url); ?>" class="img-responsive" alt="" />
</div>
<?php endif; ?>

<?php else :?>

<div class="col-md-4 col-sm-5">

<img src="<?php echo esc_url($image); ?>"class="img-responsive" alt="Exemple">

<?php ?>

</div>

<?php endif; ?>



Second solution:
Remove unnecessary code

<?php if ( is_single() ) : ?>

<!--Standard wp post-type is obviously post and page only -->
<?php if ( 'post' == get_post_type() ) : ?>
<div class="col-md-12 col-sm-12 marginbot40">
<img src="<?php echo esc_url($image); ?>"class="img-responsive" alt="Exemple">
</div>
<?php endif; ?>

<?php endif; ?>