I’m new to wordpress. Is it possible to define a variable inside the pages-admin area?
I got an if-else statement in my template. It creates a text-output. But i don’t want to define this text hard coded inside the template-file. I use polylang-plugin for multi-language support. So I’d like to set up a page for each language, which should define its own $msg text.
Otherwise I’d need to check the languages inside the template to define the correct message in here – or use an extra template for each language. I don’t beleave, that this is the only solution.
I’m looking for something like this ->
in template.php:
if (empty($statement)) {
echo $msg1;
}
in admin-pages something like:
$msg1 = "no entries found";
how do I define vars outside the template-file?
You can define variables within your theme functions file (functions.php) or a custom plugin. You can take advantage of these via hooks and filters within WordPress core and your theme if it is supported. Here’s an example using functions.php.
This will insert the echoed variable into any template file that uses
the_content
. Although very basic, this functionality will give you plenty of flexibility.