admin管理员组文章数量:1415460
is there a filter for removing style-tags from the <head></head>
area in wordpress?
I want remove this style for instance:
<head>
<style>
@import url(';display=swap');
</style>
</head>
I already achieved to remove link-tags by using this wordpress filter and some regex:
add_filter( 'style_loader_tag', 'removeGoogleLinks');
I guess i havbe to use wp_head somehow but I'm not sure how to use this as filter?
add_filter( 'wp_head', $removeGoogleFontStyle);
public function removeGoogleFontStyle($content){
//Filter googleapi styles with regex but
//how to use this funtion/filter?
}
is there a filter for removing style-tags from the <head></head>
area in wordpress?
I want remove this style for instance:
<head>
<style>
@import url('https://fonts.googleapis/css?family=Chilanka&display=swap');
</style>
</head>
I already achieved to remove link-tags by using this wordpress filter and some regex:
add_filter( 'style_loader_tag', 'removeGoogleLinks');
I guess i havbe to use wp_head somehow but I'm not sure how to use this as filter?
add_filter( 'wp_head', $removeGoogleFontStyle);
public function removeGoogleFontStyle($content){
//Filter googleapi styles with regex but
//how to use this funtion/filter?
}
Share
Improve this question
edited Sep 8, 2019 at 12:07
murcoder
asked Sep 8, 2019 at 11:55
murcodermurcoder
991 gold badge1 silver badge13 bronze badges
0
1 Answer
Reset to default 1My solution removes now all <link></link>
tags and <style>@import url()</style>
googleapi entries in the given HTML:
add_action( 'wp_footer', 'SPDSGVOPublic::removeGoogleFonts' );
/**
* Remove all occurrences of google fonts
*/
public static function removeGoogleFonts()
{
ob_start();
$content = ob_get_clean();
$patternImportUrl = '/(@import[\s]url\((?:"|\')((?:https?:)?\/\/fonts\.googleapis\\/css(?:(?!\1).)+)(?:"|\')\)\;)/';
$patternLinkTag = '/<link(?:\s+(?:(?!href\s*=\s*)[^>])+)?(?:\s+href\s*=\s*([\'"])((?:https?:)?\/\/fonts\.googleapis\\/css(?:(?!\1).)+)\1)(?:\s+[^>]*)?>/';
preg_match_all($patternImportUrl, $content, $matchesImportUrl);
preg_match_all($patternLinkTag, $content, $matchesLinkTag);
$matches = array_merge($matchesImportUrl,$matchesLinkTag);
foreach( $matches as $match ) {
$content = str_replace( $match, '', $content );
}
echo $content;
}
本文标签: filtersRemove style tags from head
版权声明:本文标题:filters - Remove style tags from head 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745175661a2646226.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论