Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replacing content with the_content filter hook #710

Open
titamrtn opened this issue Sep 17, 2024 · 0 comments
Open

Replacing content with the_content filter hook #710

titamrtn opened this issue Sep 17, 2024 · 0 comments

Comments

@titamrtn
Copy link

Problem Description

We actually use the hook filter "the_content" to change link to span if it contains /go/ word

add_filter( 'the_content', 'link_change', PHP_INT_MAX, 1 );
function link_change( $content ) {
	
	$content = preg_replace_callback( '/<a[^>]*href="([^"]*\/go\/[^"]*)"[^>]*>(.*?)<\/a>/i', function ( $matches ) {
		$classes = [];
		if ( preg_match_all( '/class="([^"]*)"/i', $matches[0], $classMatches ) ) {
			$classes = explode( ' ', $classMatches[1][0] );
		}

		$classes[] = 'qcd';

		$href = $matches[1];
		$text = $matches[2];

		return '<span class="' . implode( ' ', $classes ) . '">' . $text . '</span>';
	}, $content );

	return $content;
}

It works fine on page and posts.

Now we have a custom "page" or whatever it is created for a specific category using the Divi Theme Builder, and the filter "the_content" seems to not be applied on it.

The question: is the content created in Theme Builder applying the filter 'the_content'? if not how can we have the same behavior ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant