Ioana Pristoleanu Ioana Pristoleanu - 3 months ago 6
PHP Question

Wordpress - Include php file with name of category?

I'm trying to include a php file which contains description for each of my categories. So when I'm in category Cat1, I want to see the description of Cat1, when I'm in Cat2, the description for Cat2 and so on.

I tried the following code:

<?php
include (single_cat_title() . '.php');
?>


But it just displays the title of the category. When I tried this:

<?php
$name = "Cat1";
include ($name . '.php');
?>


it works, but if i add single_cat_title() instead of the hard coded "Cat1" it stops working.

Thank you!

Answer

try this:

<?php include (single_cat_title('',false) . '.php'); ?>

Referenced from: https://developer.wordpress.org/reference/functions/single_cat_title/#parameters