Add Custom Link Rel Attribute

Hire Now!

Whether you’re looking to launch your brand, showcase your portfolio, or open an online store, we’re here to bring your ideas to life.

  • Post Created: 2 months ago
  • Views: 1

Add Custom Link Rel Attribute

Reading Time: 1 Minute

Understanding the Hook: wp_nav_menu_items

The wp_nav_menu_items filter allows you to modify menu items and add custom attributes like rel.

Why Use This Hook?

  • Enhance menu item attributes for accessibility or SEO.
  • Add tracking or metadata to links.

How It Works

Modify the HTML output of menu items.

Code Example

function add_custom_rel_to_menu_items($items) {
    return str_replace('<a ', '<a rel="nofollow" ', $items);
}
add_filter('wp_nav_menu_items', 'add_custom_rel_to_menu_items');

Content Harmony: On-Site Data

Harmony

Contents

Website security is a top priority for WordPress site owners. From brute force attacks to malware, threats are everyw…

Affiliate marketing is a proven way to monetize your website and drive additional revenue streams. WordPress affilia…

Integrating secure and efficient payment gateways is essential for any e-commerce site. WordPress payment gateway pl…

WooCommerce is one of the most popular platforms for building online stores, but its functionality can be significan…

Discussion