: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if ( is_numeric( $post->post_name ) || str_contains( get_option( 'permalink_structure' ), '%category%' ) ) {
$name = 'attachment/' . $post->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker.
$name = $post->post_name;
if ( ! str_contains( $parentlink, '?' ) ) {
$link = user_trailingslashit( trailingslashit( $parentlink ) . '%postname%' );
$link = str_replace( '%postname%', $name, $link );
} elseif ( $wp_rewrite->using_permalinks() && ! $leavename ) {
$link = home_url( user_trailingslashit( $post->post_name ) );
$link = home_url( '/?attachment_id=' . $post->ID );
* Filters the permalink for an attachment.
* @since 5.6.0 Providing an empty string will now disable
* the view attachment page link on the media modal.
* @param string $link The attachment's permalink.
* @param int $post_id Attachment ID.
return apply_filters( 'attachment_link', $link, $post->ID );
* Retrieves the permalink for the year archives.
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
* @param int|false $year Integer of year. False for current year.
* @return string The permalink for the specified year archive.
function get_year_link( $year ) {
$year = current_time( 'Y' );
$yearlink = $wp_rewrite->get_year_permastruct();
if ( ! empty( $yearlink ) ) {
$yearlink = str_replace( '%year%', $year, $yearlink );
$yearlink = home_url( user_trailingslashit( $yearlink, 'year' ) );
$yearlink = home_url( '?m=' . $year );
* Filters the year archive permalink.
* @param string $yearlink Permalink for the year archive.
* @param int $year Year for the archive.
return apply_filters( 'year_link', $yearlink, $year );
* Retrieves the permalink for the month archives with year.
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
* @param int|false $year Integer of year. False for current year.
* @param int|false $month Integer of month. False for current month.
* @return string The permalink for the specified month and year archive.
function get_month_link( $year, $month ) {
$year = current_time( 'Y' );
$month = current_time( 'm' );
$monthlink = $wp_rewrite->get_month_permastruct();
if ( ! empty( $monthlink ) ) {
$monthlink = str_replace( '%year%', $year, $monthlink );
$monthlink = str_replace( '%monthnum%', zeroise( (int) $month, 2 ), $monthlink );
$monthlink = home_url( user_trailingslashit( $monthlink, 'month' ) );
$monthlink = home_url( '?m=' . $year . zeroise( $month, 2 ) );
* Filters the month archive permalink.
* @param string $monthlink Permalink for the month archive.
* @param int $year Year for the archive.
* @param int $month The month for the archive.
return apply_filters( 'month_link', $monthlink, $year, $month );
* Retrieves the permalink for the day archives with year and month.
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
* @param int|false $year Integer of year. False for current year.
* @param int|false $month Integer of month. False for current month.
* @param int|false $day Integer of day. False for current day.
* @return string The permalink for the specified day, month, and year archive.
function get_day_link( $year, $month, $day ) {
$year = current_time( 'Y' );
$month = current_time( 'm' );
$day = current_time( 'j' );
$daylink = $wp_rewrite->get_day_permastruct();
if ( ! empty( $daylink ) ) {
$daylink = str_replace( '%year%', $year, $daylink );
$daylink = str_replace( '%monthnum%', zeroise( (int) $month, 2 ), $daylink );
$daylink = str_replace( '%day%', zeroise( (int) $day, 2 ), $daylink );
$daylink = home_url( user_trailingslashit( $daylink, 'day' ) );
$daylink = home_url( '?m=' . $year . zeroise( $month, 2 ) . zeroise( $day, 2 ) );
* Filters the day archive permalink.
* @param string $daylink Permalink for the day archive.
* @param int $year Year for the archive.
* @param int $month Month for the archive.
* @param int $day The day for the archive.
return apply_filters( 'day_link', $daylink, $year, $month, $day );
* Displays the permalink for the feed type.
* @param string $anchor The link's anchor text.
* @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'.
* Default is the value of get_default_feed().
function the_feed_link( $anchor, $feed = '' ) {
$link = '<a href="' . esc_url( get_feed_link( $feed ) ) . '">' . $anchor . '</a>';
* Filters the feed link anchor tag.
* @param string $link The complete anchor tag for a feed link.
* @param string $feed The feed type. Possible values include 'rss2', 'atom',
* or an empty string for the default feed type.
echo apply_filters( 'the_feed_link', $link, $feed );
* Retrieves the permalink for the feed type.
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
* @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'.
* Default is the value of get_default_feed().
* @return string The feed permalink.
function get_feed_link( $feed = '' ) {
$permalink = $wp_rewrite->get_feed_permastruct();
if ( str_contains( $feed, 'comments_' ) ) {
$feed = str_replace( 'comments_', '', $feed );
$permalink = $wp_rewrite->get_comment_feed_permastruct();
if ( get_default_feed() === $feed ) {
$permalink = str_replace( '%feed%', $feed, $permalink );
$permalink = preg_replace( '#/+#', '/', "/$permalink" );
$output = home_url( user_trailingslashit( $permalink, 'feed' ) );
$feed = get_default_feed();
if ( str_contains( $feed, 'comments_' ) ) {
$feed = str_replace( 'comments_', 'comments-', $feed );
$output = home_url( "?feed={$feed}" );
* Filters the feed type permalink.
* @param string $output The feed permalink.
* @param string $feed The feed type. Possible values include 'rss2', 'atom',
* or an empty string for the default feed type.
return apply_filters( 'feed_link', $output, $feed );
* Retrieves the permalink for the post comments feed.
* @param int $post_id Optional. Post ID. Default is the ID of the global `$post`.
* @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'.
* Default is the value of get_default_feed().
* @return string The permalink for the comments feed for the given post on success, empty string on failure.
function get_post_comments_feed_link( $post_id = 0, $feed = '' ) {
$post_id = absint( $post_id );
$feed = get_default_feed();
$post = get_post( $post_id );
// Bail out if the post does not exist.
if ( ! $post instanceof WP_Post ) {
$unattached = 'attachment' === $post->post_type && 0 === (int) $post->post_parent;
if ( get_option( 'permalink_structure' ) ) {
if ( 'page' === get_option( 'show_on_front' ) && (int) get_option( 'page_on_front' ) === $post_id ) {
$url = _get_page_link( $post_id );
$url = get_permalink( $post_id );
$url = home_url( '/feed/' );
if ( get_default_feed() !== $feed ) {
$url = add_query_arg( 'attachment_id', $post_id, $url );
$url = trailingslashit( $url ) . 'feed';
if ( get_default_feed() !== $feed ) {
$url = user_trailingslashit( $url, 'single_feed' );
'attachment_id' => $post_id,
} elseif ( 'page' === $post->post_type ) {
* Filters the post comments feed permalink.
* @param string $url Post comments feed permalink.
return apply_filters( 'post_comments_feed_link', $url );
* Displays the comment feed link for a post.
* Prints out the comment feed link for a post. Link text is placed in the
* anchor. If no link text is specified, default text is used. If no post ID is
* specified, the current post is used.
* @param string $link_text Optional. Descriptive link text. Default 'Comments Feed'.
* @param int $post_id Optional. Post ID. Default is the ID of the global `$post`.
* @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'.
* Default is the value of get_default_feed().
function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '' ) {
$url = get_post_comments_feed_link( $post_id, $feed );
if ( empty( $link_text ) ) {
$link_text = __( 'Comments Feed' );
$link = '<a href="' . esc_url( $url ) . '">' . $link_text . '</a>';
* Filters the post comment feed link anchor tag.
* @param string $link The complete anchor tag for the comment feed link.
* @param int $post_id Post ID.
* @param string $feed The feed type. Possible values include 'rss2', 'atom',
* or an empty string for the default feed type.
echo apply_filters( 'post_comments_feed_link_html', $link, $post_id, $feed );
* Retrieves the feed link for a given author.
* Returns a link to the feed for all posts by a given author. A specific feed
* can be requested or left blank to get the default feed.
* @param int $author_id Author ID.
* @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'.
* Default is the value of get_default_feed().
* @return string Link to the feed for the author specified by $author_id.
function get_author_feed_link( $author_id, $feed = '' ) {
$author_id = (int) $author_id;
$permalink_structure = get_option( 'permalink_structure' );
$feed = get_default_feed();
if ( ! $permalink_structure ) {
$link = home_url( "?feed=$feed&author=" . $author_id );
$link = get_author_posts_url( $author_id );
if ( get_default_feed() === $feed ) {
$feed_link = "feed/$feed";
$link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' );
* Filters the feed link for a given author.
* @param string $link The author feed link.
* @param string $feed Feed type. Possible values include 'rss2', 'atom'.
$link = apply_filters( 'author_feed_link', $link, $feed );
* Retrieves the feed link for a category.
* Returns a link to the feed for all posts in a given category. A specific feed
* can be requested or left blank to get the default feed.
* @param int|WP_Term|object $cat The ID or category object whose feed link will be retrieved.
* @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'.
* Default is the value of get_default_feed().
* @return string Link to the feed for the category specified by `$cat`.
function get_category_feed_link( $cat, $feed = '' ) {
return get_term_feed_link( $cat, 'category', $feed );
* Retrieves the feed link for a term.
* Returns a link to the feed for all posts in a given term. A specific feed
* can be requested or left blank to get the default feed.
* @param int|WP_Term|object $term The ID or term object whose feed link will be retrieved.
* @param string $taxonomy Optional. Taxonomy of `$term_id`.
* @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'.
* Default is the value of get_default_feed().
* @return string|false Link to the feed for the term specified by `$term` and `$taxonomy`.
function get_term_feed_link( $term, $taxonomy = '', $feed = '' ) {
if ( ! is_object( $term ) ) {
$term = get_term( $term, $taxonomy );
if ( empty( $term ) || is_wp_error( $term ) ) {
$taxonomy = $term->taxonomy;
$feed = get_default_feed();
$permalink_structure = get_option( 'permalink_structure' );
if ( ! $permalink_structure ) {
if ( 'category' === $taxonomy ) {
$link = home_url( "?feed=$feed&cat=$term->term_id" );
} elseif ( 'post_tag' === $taxonomy ) {
$link = home_url( "?feed=$feed&tag=$term->slug" );
$t = get_taxonomy( $taxonomy );
$link = home_url( "?feed=$feed&$t->query_var=$term->slug" );
$link = get_term_link( $term, $term->taxonomy );
if ( get_default_feed() === $feed ) {
$feed_link = "feed/$feed";
$link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' );
if ( 'category' === $taxonomy ) {
* Filters the category feed link.
* @param string $link The category feed link.
* @param string $feed Feed type. Possible values include 'rss2', 'atom'.
$link = apply_filters( 'category_feed_link', $link, $feed );
} elseif ( 'post_tag' === $taxonomy ) {
* Filters the post tag feed link.
* @param string $link The tag feed link.
* @param string $feed Feed type. Possible values include 'rss2', 'atom'.
$link = apply_filters( 'tag_feed_link', $link, $feed );
* Filters the feed link for a taxonomy other than 'category' or 'post_tag'.
* @param string $link The taxonomy feed link.