How to delete the permalink (landing pages) of ima

2019-07-12 00:14发布

I notice every image uploaded on wordpress website will have a separate page(a permalink to the image)

like this : https://www.knexusgroup.com/linkedin_logo_v1/

This is not good, how do I remove these page for every image? Every image have already CDN link.

I have got hold on images uploaded for blog post using Yost plugin but these images are uploaded to pages & are not attached to the particular page. These images are not looking good on the search result.

Please help me how can I remove this from wordpress.

1条回答
做个烂人
2楼-- · 2019-07-12 00:46

Create a new file called image.php in your theme. Insert the code below in your image.php file,

<?php
global $post;
if ( $post && $post->post_parent ) {
wp_redirect( esc_url( get_permalink( $post->post_parent ) ), 301 );
exit;
} else {
wp_redirect( esc_url( home_url( '/' ) ), 301 );
exit;
}
查看更多
登录 后发表回答