Skip to content

haseemajaz/Remove-Product-Description-Hyperlinks-woocommerce

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

Remove-Product-Description-Hyperlinks-woocommerce

This handy piece of code allows you to enhance the presentation of your WooCommerce product descriptions by removing hyperlinks, making your product pages cleaner and more user-friendly.

What Does This Code Snippet Do?

When you're running an online store using WooCommerce, you might have product descriptions with hyperlinks that link to other pages or products. While hyperlinks are valuable in many contexts, sometimes they can clutter your product descriptions or distract potential customers. This is where the "Remove Product Description Hyperlinks" code snippet comes to the rescue. This simple WordPress code snippet is designed to be added to your theme's functions.php file. It targets product pages specifically. When added and activated, it scans the product description content and intelligently removes any hyperlinks, leaving behind only the clean, unlinked text. This helps to streamline your product pages, creating a more focused and aesthetically pleasing shopping experience for your customers.

How to Use This Code Snippet

If you want to integrate this functionality into your WooCommerce store, follow these simple steps:

Access the functions.php File:

Log in to your WordPress dashboard. Go to "Appearance" > "Theme Editor." Select your active theme. Add the Code Snippet:

On the right side, find and click on the functions.php file. Scroll to the bottom of the file and paste the following code snippet:

Code Snippet

function remove_product_description_hyperlinks($content) {
    if (is_product()) {
        // Remove hyperlinks from the product description
        $content = preg_replace('/<a(.*?)>(.*?)<\/a>/', '$2', $content);
    }
    return $content;
}
add_filter('the_content', 'remove_product_description_hyperlinks', 20);

Save Changes:

Click the "Update File" button to save your changes. Enjoy Clean Product Descriptions:

That's it! The code snippet is now active in your WooCommerce store. Visit any product page, and you'll notice that all hyperlinks within the product description have been gracefully removed, leaving only the plain text.

Customization You can further customize the behavior of this code snippet by modifying it to suit your specific needs. For instance, you can adjust the regular expression pattern in the code to handle different types of hyperlinks or modify the priority of the filter hook.

Contributions and Issues This open-source code snippet is hosted on GitHub to encourage collaboration and improvements from the community. If you have any ideas for enhancements or discover any issues, please feel free to open an issue on GitHub. We appreciate your involvement in making this code snippet even more useful.

License This "Remove Product Description Hyperlinks" code snippet is distributed under the GNU General Public License v2.0. It's free to use, modify, and distribute according to the terms of the license.

Thank you for considering this code snippet for your WooCommerce store. We hope it helps you create a cleaner and more engaging shopping experience for your customers. Happy selling!