Using WordPress ‘get_index_rel_link()’ PHP function

The get_index_rel_link() WordPress PHP function retrieves the site index relational link.

Usage

echo get_index_rel_link();

Parameters

This function has no parameters.

More information

See WordPress Developer Resources: get_index_rel_link

Examples

In this example, we’ll display the index relational link in the head section of your WordPress theme.

function add_index_rel_link_to_head() {
    echo get_index_rel_link();
}
add_action('wp_head', 'add_index_rel_link_to_head');

In this example, we add the index relational link to the RSS feed of your site.

function add_index_rel_link_to_feed() {
    echo get_index_rel_link();
}
add_action('rss2_head', 'add_index_rel_link_to_feed');

In this example, we create a custom function that outputs the index relational link along with other metadata.

function output_metadata() {
    echo get_index_rel_link();
    // Output other metadata...
}

In this example, we create a custom hook and add the index relational link to it.

function custom_hook() {
    do_action('custom_hook_action');
}

function add_index_rel_link_to_custom_hook() {
    echo get_index_rel_link();
}
add_action('custom_hook_action', 'add_index_rel_link_to_custom_hook');

In this example, we display the index relational link only on the homepage.

function add_index_rel_link_on_homepage() {
    if (is_home()) {
        echo get_index_rel_link();
    }
}
add_action('wp_head', 'add_index_rel_link_on_homepage');