Skip to content

Instantly share code, notes, and snippets.

@swinggraphics
Forked from msaari/functions.php
Last active February 21, 2022 15:36
Show Gist options
  • Select an option

  • Save swinggraphics/10fd04ddb9dcffa4a4c0a1e324be621c to your computer and use it in GitHub Desktop.

Select an option

Save swinggraphics/10fd04ddb9dcffa4a4c0a1e324be621c to your computer and use it in GitHub Desktop.
Increases the weight for specified HTML tags
<?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' );
@swinggraphics
Copy link
Copy Markdown
Author

Now included in the Relevanssi knowledge base.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment