This doest not works:
Warning: in_array() expects parameter 2 to be array, null given
$non_area_page = array(160951,160955); // This does not work
add_filter( 'term_link',change_term_name , 10, 3 );
function change_term_name( $termlink, $term, $taxonomy )
{
/*If on page */
if(is_page()){
$current_id = get_queried_object_id();
$current_post = get_post($current_id);
$slug = $current_post->post_name;
if(!in_array($current_id,$non_area_page)) // array is defined in start of code above
$termlink = esc_url( add_query_arg( ['tag' => $slug], $termlink ) );
}
return $termlink;
}
Below code works: (Only difference is array is not defined outside function)
add_filter( 'term_link',change_term_name , 10, 3 );
function change_term_name( $termlink, $term, $taxonomy )
{
/*If on page */
if(is_page()){
$current_id = get_queried_object_id();
$current_post = get_post($current_id);
$slug = $current_post->post_name;
if(!in_array($current_id,array(160951,160955))) // directly passed array
$termlink = esc_url( add_query_arg( ['tag' => $slug], $termlink ) );
}
return $termlink;
}
Is that is related to defining array globally, if so how we do that In WordPress, Please suggest ?
Thanks!