Answer the question
In order to leave comments, you need to log in
Is it possible to "filter" content instead of a shortcode?
Is it possible to do a content filter instead of registering a shortcode? What is bad/good about this solution?
Those.
function my_funct($content){
global $post;
$out = $content;
здесь ищем в $out [my_shortcode] и если находим, заменяем на нужный код
return $out;
}
Answer the question
In order to leave comments, you need to log in
Of course, you can filter the content.
Here is an example of content filtering that I use. The following function filters the content (the_content) and adds nofollow noopener noreferrer to all outgoing links
function add_nofollow_content($content) {
$content = preg_replace_callback(
'/<a[^>]*href=["|\']([^"|\']*)["|\'][^>]*>([^<]*)<\/a>/i',
function($m) {
if (strpos($m[1], "md7.info") === false)
return '<a href="'.$m[1].'" rel="nofollow noopener noreferrer" target="_blank">'.$m[2].'</a>';
else
return '<a href="'.$m[1].'" target="_blank">'.$m[2].'</a>';
},
$content);
return $content;
}
add_filter('the_content', 'add_nofollow_content');
First, you can filter content with regular expressions. And it's slow.
Second, shortcodes also work on regular expressions, all of a sudden.
Third - if you are going to filter exactly [my_shortcode], then what is the profit? Or am I missing something?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question