-
-
Save swinggraphics/10fd04ddb9dcffa4a4c0a1e324be621c to your computer and use it in GitHub Desktop.
Increases the weight for specified HTML tags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function rlv_html_tag_boost( $content ) { | |
$weightings = [ | |
'h1' => 5, | |
'h2' => 4, | |
'h3' => 2, | |
'strong' => 1, | |
]; | |
foreach ( $weightings as $tag => $weight ) { | |
if ( preg_match_all( "#<$tag.*?>(.*?)</$tag>#", $content, $elements ) ) { | |
foreach ( $elements[1] as $el_content ) { | |
while ( 0 < $weight-- ) { | |
$content .= " $el_content"; | |
} | |
} | |
} | |
} | |
return $content; | |
} | |
add_filter( 'relevanssi_post_content', 'rlv_html_tag_boost' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now included in the Relevanssi knowledge base.