我在/wp-content/plugins
目錄下創建了一個名爲customshortcode的文件夾。 add_shortcode command應該將短代碼與函數鏈接起來。如何在Wordpress中創建簡單的自定義短代碼?
在/wp-content/plugins/customshorcode/
我創建2個文件:main.php
和主要的PHP test.php
內容是:
<?php require_once('../../../wp-includes/shortcodes.php'); ?>
<?php function custom_shortcode_func() {
include_once('test.php');
}
add_shortcode('customshortcode','custom_shortcode_func');
?>
而且test.php的只是顯示一個分割塊:
<style>.testdiv{border:1px solid black; width:300px; heigh:300px;}</style>
<div class="testdiv"></div>
我第一運行/wp-content/plugins/customshorcode/main.php
文件以查看沒有錯誤和簡單的白色屏幕。我認爲應該保存短代碼。
但是,當我在頁面中輸入[customshortcode]時,我沒有得到顯示的部分,而是改爲使用文本[customshortcode]。
我想我需要將頁面類型鏈接到插件或類似的東西。你能幫我嗎?
在哪裏,你如何在頁面中添加[customshortcode]?在你的'test.php'中寫入 –
寫:'return'
';'。爲什麼你要包含'/ wp-includes/shortcodes.php'? –因爲沒有它,當我到main.php在URL欄中運行它時,我得到: 致命錯誤:調用未定義的函數add_shortcode()在C:\ MAMP \ htdocs \ new \ wp-content \ plugins \第8行的customshortcode \ main.php – GRS