I'm trying to do something that seems really simple but I can't figure it out.
In my category template, I have this shortcode:
<?php echo do_shortcode( '[jobs categories="manufacturing"]' ); ?>
I also have this to show the title of the category:
<?php single_cat_title(); ?>
I would like to put them both together so I can pass the category into the shortcode so it fetches the correct job category listings. So I created this:
<?php $category = single_cat_title(); ?>
<?php echo do_shortcode('[jobs categories=' . $category . ']'); ?>
but it doesn't seem to work properly - Am I doing something wrong? Is this even possible?
Many thanks!!
single_cat_title()doesn't imply that it returns anything, but your second example assumes that it does. Does it?single_cat_title()function appears to output data to the browser, but the function itself isn't returning anything (or at least not what you expect) to code which calls that function. This is where some introductory PHP tutorials will be helpful for you. Focus on the structure of building and using functions. You need to get the value in your code, not just on the page.