The parent_post_rel_link WordPress PHP filter allows you to modify the “rel” attribute for the parent post navigation link.
Usage
add_filter('parent_post_rel_link', 'modify_parent_post_rel_link'); function modify_parent_post_rel_link($link) { // your custom code here return $link; }
Parameters
- $link (string): The HTML anchor element containing the parent post navigation link.
More information
See WordPress Developer Resources: parent_post_rel_link
Examples
Change the ‘rel’ attribute value
Update the “rel” attribute value of the parent post navigation link:
add_filter('parent_post_rel_link', 'change_rel_attribute_value'); function change_rel_attribute_value($link) { return str_replace('rel="parent"', 'rel="alternate"', $link); }
Add a custom class to the parent post link
Add a custom CSS class to the parent post navigation link:
add_filter('parent_post_rel_link', 'add_custom_class_to_parent_link'); function add_custom_class_to_parent_link($link) { return str_replace('<a ', '<a class="custom-class" ', $link); }
Add a custom data attribute
Add a custom “data” attribute to the parent post navigation link:
add_filter('parent_post_rel_link', 'add_custom_data_attribute'); function add_custom_data_attribute($link) { return str_replace('<a ', '<a data-custom="value" ', $link); }
Change the parent post link text
Modify the text of the parent post navigation link:
add_filter('parent_post_rel_link', 'change_parent_link_text'); function change_parent_link_text($link) { return preg_replace('/>([^<]+)</', '>New Link Text<', $link); }
Remove the parent post link
Completely remove the parent post navigation link:
add_filter('parent_post_rel_link', 'remove_parent_link'); function remove_parent_link($link) { return ''; }