Change Suggested Phrases conditionally
PreviousIndex Table – Indexing ACF repeater field titles and contentsNextHow to add shortcode to the results content?
Last updated
Last updated
add_filter("asp_suggested_phrases", "asp_change_sugg_phrase_cond", 10, 2);
function asp_change_sugg_phrase_cond($phrases, $sid) {
// If the current post/page/cpt IDs is in this array
// then the alternative phrases are displayed.
// Change this to the post/page/cpt IDs you want
$cpt_array = array( 1, 2, 3 );
// The alternative phrases array. Add/remove keywords you want as alternatives.
$alt_phrases = array(
"alt phrase 1",
"alt phrase 2",
"alt phrase 3"
);
// Change this to true if one of the pages is the home page as well
$allow_home = false;
//-- Do NOT change anything below this line! --
$post_id = get_the_ID();
if ( is_home() && !$allow_home) return $phrases;
if ( $post_id === false ) return $phrases;
if ( in_array($post_id, $cpt_array) ) return $alt_phrases;
return $phrases;
}