WordPressで画像のリンクに、attachment pageがあるのでR。
例えば、ここの記事にあるようにプラグイン「Easy Image Display」では、
[sb_easy_image num="1" order="random" link="lightbox"]
のようにlinkを指定できるのでRが、link=”attachment”のようにも指定できるのでR。
ただし、attachment pageはattachment pageであって、post pageとは違うのでR。
そこで、post pageへリンクするには、テーマのfunction.phpに、ここにあるように、
add_action( 'template_redirect', 'wpsites_attachment_redirect' ); function wpsites_attachment_redirect(){ global $post; if ( is_attachment() && isset($post->post_parent) && is_numeric($post->post_parent) && ($post->post_parent != 0) ) : wp_redirect( get_permalink( $post->post_parent ), 301 ); exit(); wp_reset_postdata(); endif; }
を追加すると、attachment pageへのリンクがpost pageへのリンクとなったのでR。




この記事をシェアできます。