wordpress output var in template that is defined by admin-pages

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.

Read More

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?

Related posts

Leave a Reply

1 comment

  1. 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.

    add_filter('the_content', 'my_custom_var');
    function my_custom_var() {
            $my_var = 'something different'
            echo $my_var;
        }
    

    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.