开发者

repeat wordpress code

开发者 https://www.devze.com 2023-04-13 08:25 出处:网络
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...

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();
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消