So lets say i have a php file that contains
$title="Website | Categories";
And my header.inc file includes <title><?=$title?></title> which will output the title name.
But lets say i also have a variable on my php page called 'cat_name'
How can i add ‘cat_name’ into $title="Website | Categories"; Would it be like
$title="Website | Categories 'cat_name'";
These will work:
$title = "Website | Categories " . $cat_name;$title = "Website | Categories $cat_name";This will not work:
$title = 'Website | Categories $cat_name';If a string is in double-quotes it will parse any variables inside of it. However, if the string is in single quotes it will not.
If you want to get a little fancier there are various ways to append the category name with another vertical pipe, like
Website | Categories | My Category.The simplest is probably using the ternary operator to detect if
$cat_nameis set and append text to the $title string.You could also create an array and add each element of your navigation to it (Website, Category, cat_name, sub_cat, sub_sub_cat, …) then use an implode statement to turn it into a string.