Using WordPress ‘index_rel_link()’ PHP function

The index_rel_link() WordPress PHP function displays a relational link for the site index.

Usage

index_rel_link();

Parameters

  • None

More information

See WordPress Developer Resources: index_rel_link

Examples

In this example, the index_rel_link() function is used in the header of a WordPress theme to display the site index link.

// In header.php
<head>
...
  <?php index_rel_link(); ?>
...
</head>

In this example, a custom hook is created to display the site index link using the index_rel_link() function. This custom hook can then be added to your theme.

// In functions.php
function my_custom_index_rel_link() {
  index_rel_link();
}
add_action('wp_head', 'my_custom_index_rel_link');

In this example, the index_rel_link() function is used to display the site index link only on specific post types.

// In functions.php
function conditional_index_rel_link() {
  if (is_singular('post')) {
    index_rel_link();
  }
}
add_action('wp_head', 'conditional_index_rel_link');

In this example, the index_rel_link() function is used along with other attributes to display the site index link with custom attributes.

// In header.php
<head>
...
  <?php index_rel_link(); ?>
  <link rel="alternate" type="application/rss+xml" title="Site Name - RSS Feed" href="<?php bloginfo('rss2_url'); ?>" />
...
</head>

In this example, the index_rel_link() function is removed from the wp_head action to prevent the site index link from being displayed.

// In functions.php
remove_action('wp_head', 'index_rel_link');