2011-11-23 80 views
0

我定義了一個名爲「firstname」的工作函數,它可以正常執行。在我的第二個功能中,我想引用它。我究竟做錯了什麼?我知道我使用的PHP調用不起作用,但希望您瞭解我的目標是什麼。這當然是在我的functions.php文件中。在wordpress函數中調用之前定義的函數

// Define function to get form field values: 

// Working: 

function firstname(){ 
$firstname = $_GET["Field1"]; 
echo $firstname; 
} 

// Find and replace values: 

function replace_text_wps($text) { 
    $text = str_replace('firstname', '<?php firstname(); ?>', $text); 
    $text = str_replace('tech support', '<a href="/techsupport">Tech support</a>',   $text); 
    $text = str_replace('computers', '<a href="/computers">Computers</a>', $text); 
    return $text; 
} 
add_filter('the_content', 'replace_text_wps'); 
+0

我不認爲你想回聲'$ firstname'回來。我想你想'返回$ firstname;'。 – mrtsherman

+0

謝謝!這解決了我的渲染問題。 – gabearnold

回答

1

如果我理解你正在試圖做正確的東西,你可以用

$text = str_replace('firstname', firstname(), $text); 

WordPress的走在文本將不會重新解析任何PHP已經經過過濾器後消失。

此外,正如mrtsherman所評論的,您需要return $firstname中的firstname()函數。

+0

好吧,我設法弄清楚,並指出我應該返回的價值幫助我找出最後一部分,因爲它不使用回顯正確。謝謝 !! – gabearnold

+0

'$ text = str_replace('firstname',$ firstname,$ text);'thanks @mrtsherman and @Juhana – gabearnold

+0

@gabearnold - 一定要將Juhana的答案標記爲正確的!很高興它現在爲你工作。 – mrtsherman

相關問題