diff --git a/src/wp-includes/link-template.php b/src/wp-includes/link-template.php index b580a0a8a2..0b8354a92b 100644 --- a/src/wp-includes/link-template.php +++ b/src/wp-includes/link-template.php @@ -1124,6 +1124,19 @@ function get_post_type_archive_link( $post_type ) { if ( ! $post_type_obj = get_post_type_object( $post_type ) ) return false; + if ( 'post' === $post_type ) { + $show_on_front = get_option( 'show_on_front' ); + $page_for_posts = get_option( 'page_for_posts' ); + + if ( 'page' == $show_on_front && $page_for_posts ) { + $link = get_permalink( $page_for_posts ); + } else { + $link = get_home_url(); + } + /** This filter is documented in wp-includes/link-template.php */ + return apply_filters( 'post_type_archive_link', $link, $post_type ); + } + if ( ! $post_type_obj->has_archive ) return false; diff --git a/tests/phpunit/tests/link/getPostTypeArchiveLink.php b/tests/phpunit/tests/link/getPostTypeArchiveLink.php new file mode 100644 index 0000000000..bb15c16a69 --- /dev/null +++ b/tests/phpunit/tests/link/getPostTypeArchiveLink.php @@ -0,0 +1,28 @@ +assertSame( $expected, $actual ); + } + + /** + * @ticket 19902 + */ + public function test_get_post_archive_link_with_post_archive_on_a_blog_page() { + $page_for_posts = $this->factory->post->create( array( 'post_title' => 'blog-page', 'post_type' => 'page' ) ); + update_option( 'show_on_front', 'page' ); + update_option( 'page_for_posts', $page_for_posts ); + $actual = get_post_type_archive_link( 'post' ); + $expected = get_permalink( $page_for_posts ); + $this->assertSame( $expected, $actual ); + } +}