Voxel Theme Modifier – Remove Links from Users Content

As a business directory owner using the Voxel Theme, you may want to allow users and business owners to format their content using the WYSIWYG editor without worrying about external links.

Often, these users add links in their descriptions that create SEO challenges—whether they’re follow or no-follow links—when your primary focus is on maintaining a clean, well-structured directory.

The “Remove < a href > Links” modifier is a great solution for controlling how content appears on your site. This Voxel Mod allows you to automatically strip out any links added through the WYSIWYG editor while keeping the rest of the text intact.

It ensures that the editor is used purely for formatting purposes, without affecting your site’s SEO or diluting your link equity with follow or no-follow links that you don’t want to give out.

With this modifier, you can maintain full control over your site’s content, making sure that business listings stay professional and clean, without external links cluttering the page or influencing your search engine rankings.

Plus, the added security measures, such as input sanitization and output escaping, ensure that user-generated content is safe and doesn’t introduce vulnerabilities like Cross-Site Scripting (XSS).

The Code: Voxel Theme Modifier – Remove Links from Users Content

Add to your functions.php file.

add_filter( 'voxel/dynamic-tags/modifiers', function( $modifiers ) {
    class Remove_Ahref_Links extends \Voxel\Dynamic_Tags\Base_Modifier {

        // Label for the modifier
        public function get_label(): string {
            return 'Remove ahref Links';
        }

        // Unique key for the modifier
        public function get_key(): string {
            return 'remove_ahref_links';
        }

        // No input arguments are needed for this function
        public function get_arguments(): array {
            return [];
        }

        // Apply the function to remove <a href> tags while keeping the text
        public function apply( $value, $args, $group ) {
            // Check if the value is a string
            if ( !is_string( $value ) ) {
                return htmlspecialchars( $value ); // Escape and return if not a string
            }

            // Allow all HTML tags except for <a> tags
            $allowed_tags = [
                'b' => [],
                'strong' => [],
                'i' => [],
                'em' => [],
                'u' => [],
                'p' => [],
                'br' => [],
                'ul' => [],
                'ol' => [],
                'li' => [],
                'div' => [],
                'span' => [],
                'img' => [ 'src' => true, 'alt' => true, 'class' => true ],
                'h1' => [],
                'h2' => [],
                'h3' => [],
                'h4' => [],
                'h5' => [],
                'h6' => [],
                // Add any other tags you want to allow here
            ];

            // Sanitize the input, keeping all allowed HTML but removing <a> tags
            $sanitized_value = wp_kses( $value, $allowed_tags );

            // Use regex to remove <a href> tags but preserve the text inside the links
            $modified_value = preg_replace( '#<a.*?>(.*?)</a>#is', '$1', $sanitized_value );

            // Return the modified value without escaping, so allowed HTML is preserved
            return $modified_value;
        }
    }

    // Add the custom modifier to the list of available modifiers
    $modifiers['remove_ahref_links'] = \Remove_Ahref_Links::class;
    return $modifiers;
} );

To implement this solution, you’ll need to add the code to your WordPress site. You have two options for where to place this code:

Child Theme’s functions.php File:

If you’re already using a child theme (recommended for customization), simply add the PHP code to your functions.php file. This will ensure your changes are preserved even if the main Voxel theme is updated.

Code Snippets Plugin:

If you prefer not to edit theme files directly, or if you want to manage your custom code more easily, you can use the Code Snippets plugin. This plugin allows you to add custom PHP code without touching your theme files. Just create a new snippet, paste the code, and activate it.

Then apply this Voxel Mod to the Post Content dynamic tag or other text field as required.

More Articles

The Voxel WordPress Theme is a dynamic content framework with the ability to provide user listings, user profiles, conversation feeds, bookings and membership, all with dynamic visibility and full design control. The Voxel WordPress Theme is developed by the team at 27 Collective, the same team that developed the MyListing directory theme. While many of […]
This guide outlines how to implement Rank Math SEO schema markup within the Voxel WordPress Theme using the free version of Rank Math, enhancing search engine understanding and visibility of your content.   Step 1: Generate Schema MarkupUse an online schema generator to create your schema markup structure. Step 2: Adjust Rank Math SettingsDisable the […]
rank math seo schema markup guide for the voxel theme

Support me

Coffee is my fuel

All guides are available for FREE.

If this saved you time, please support my work by checking out the recommended tools or buying me a coffee.