This doesn’t actually look like a WordPress problem, but rather a lack of PHP skills unfortunately. Your problem lies in this piece of code
$custom_category_text="<p> " . $office[$office_random[0]] . ' ' . $office1[$office1_random[0]] . '</p>';
// Category ID = 1
if (in_category('1')) {
$content = $content . $custom_category_text;
}
return $content;
$custom_category_text="<p> " . $home[$home_random[0]] . ' ' . $home1[$home1_random[0]] . '</p>';
// Category ID = 2
if (in_category('2')) {
$content = $content . $custom_category_text;
}
return $content;
The code for category 2 will never work as you have already returned the variable, and you are setting two different values to two instances of $custom_category_text
as well. You can fix this with proper use of an if
else
statement. You can try something like this
if (in_category('1')) { // Category ID = 1
$custom_category_text="<p> " . $office[$office_random[0]] . ' ' . $office1[$office1_random[0]] . '</p>';
$content = $content . $custom_category_text;
}elseif(in_category('2')) { // Category ID = 2
$custom_category_text="<p> " . $home[$home_random[0]] . ' ' . $home1[$home1_random[0]] . '</p>';
$content = $content . $custom_category_text;
}
return $content;
Just replace the original code at the top of my answer with this