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

*** Disclaimer – Use at your own risk. Always make a backup. ***

Add to your Child theme’s functions.php file.

add_filter( 'voxel/dynamic-data/modifiers', function( $modifiers ) {
    class Remove_Ahref_Links_Modifier extends \Voxel\Dynamic_Data\Modifiers\Base_Modifier {
        public function get_label(): string {
            return 'Remove ahref Links';
        }

        public function get_key(): string {
            return 'remove_ahref_links';
        }

        protected function define_args(): void {
            // No additional arguments needed for this modifier
        }

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

            // Define allowed HTML tags to preserve, including inline styles
            $allowed_tags = [
                'b' => [],        // Bold
                'strong' => [],   // Strong
                'i' => [],        // Italics
                'em' => [],       // Emphasized text
                'u' => [],        // Underlined text
                'p' => [ 'style' => true ], // Paragraph with inline styles
                'br' => [],       // Line breaks
                'ul' => [],       // Unordered lists
                'ol' => [],       // Ordered lists
                'li' => [],       // List items
                'div' => [ 'style' => true ], // Div with inline styles
                'span' => [ 'style' => true ], // Span with inline styles
                'img' => [ 'src' => true, 'alt' => true, 'class' => true, 'style' => true ], // Images with inline styles
                'h1' => [ 'style' => true ], // Heading 1 with inline styles
                'h2' => [ 'style' => true ], // Heading 2 with inline styles
                'h3' => [ 'style' => true ], // Heading 3 with inline styles
                'h4' => [ 'style' => true ], // Heading 4 with inline styles
                'h5' => [ 'style' => true ], // Heading 5 with inline styles
                'h6' => [ 'style' => true ], // Heading 6 with inline styles
                'blockquote' => [ 'style' => true ], // Blockquotes with inline styles
                'pre' => [ 'style' => true ], // Preformatted text with inline styles
                'code' => [],      // Inline code
                // 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;
        }
    }

    $modifiers['remove_ahref_links'] = \Remove_Ahref_Links_Modifier::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.

Unleash Dynamic Data with Voxel!

With Voxel’s design flexibility, the possibilities are endless. Get Voxel here!

More Articles

Displaying parent categories with their child categories grouped underneath in Voxel is difficult and not directly supported by default term feed options. To achieve this, you need to use a term loop workaround that allows child terms to be looped inside a parent term preview. The steps below show how to do this using native […]
Voxel Framework is a new WordPress plugin in development that brings Voxel’s features to Bricks Builder and Gutenberg. While Voxel can create custom post types, taxonomies, and custom fields — and supports powerful dynamic data, conditional logic, and visibility rules — its real value goes far beyond content structure. Details below are speculative based on […]