How do I set a piece of code to a function in WordPress and then call that function...this was my first guess, but of course this doesn't work...
Could someone suggest how I can get this to work so I can avoid redundant code. Also if I define code in a function can I call it in different .php files, or can I only call it within that file?
<?php
// This code will never change.
function $test {开发者_运维百科
echo('test this will be a long string and repeated many times.')
}
?>
<?php
echo $test;
?>
PHP function names (unlike variables) are declared without dollar signs:
function test (
To call a function, use this format:
test();
Your code example will look like this:
<?php
// This code will never change.
function test {
echo('test this will be a long string and repeated many times.')
}
?>
<?php
test();
?>
精彩评论