Skip to content

Instantly share code, notes, and snippets.

@msaari
Created February 10, 2022 06:23
Show Gist options
  • Save msaari/7fcc25bf0b2a3ec858f641fa02e635dc to your computer and use it in GitHub Desktop.
Save msaari/7fcc25bf0b2a3ec858f641fa02e635dc to your computer and use it in GitHub Desktop.
Increases the weight for headings
<?php
add_filter( 'relevanssi_post_content', 'rlv_heading_boost' );
function rlv_heading_boost( $content ) {
if ( preg_match_all( '/<h1.*?>(.*?)<\/h1>/', $content, $h1_headings ) ) {
foreach ( $h1_headings[1] as $heading ) {
$content .= " $heading $heading $heading $heading $heading $heading $heading $heading";
}
}
if ( preg_match_all( '/<h2.*?>(.*?)<\/h2>/', $content, $h2_headings ) ) {
foreach ( $h2_headings[1] as $heading ) {
$content .= " $heading $heading $heading $heading";
}
}
if ( preg_match_all( '/<h3.*?>(.*?)<\/h3>/', $content, $h3_headings ) ) {
foreach ( $h3_headings[1] as $heading ) {
$content .= " $heading $heading";
}
}
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment