通过插件更改Wordpress的主题代码

时间:2010-03-26 16:42:03

标签: php wordpress plugins

如何使用wordpress插件更改/添加主题代码?示例:在注释之前或之后添加 - 形成几行。

1 个答案:

答案 0 :(得分:0)

您的主题需要操作挂钩。这些钩子允许您通过插件或child theme添加钩子所在的内容。

论文和专题是带有动作挂钩的WordPress主题。虽然可以很容易地为自己的主题添加动作挂钩。

在主题中,添加do_action('your_hook_name')。例如,在comments.php文件中:

do_action('after_comments_form');

现在,在插件/子主题中,添加例如

add_action('after_comments_form', 'commenting_rules');
。这意味着我们将commenting_rules()函数添加到钩子after_comments_form

commenting_rules()功能可能如下所示:


function commenting_rules(){
    echo "No spam or similar, read our <a href=\"" . bloginfo('url') . "\"/commenting-rules\">Commenting Rules</a>";
}

请务必在add_action()功能下添加commenting_rules()功能。

Themeshaper(Thematic的创建者)有一个great article on that。 Nathan Rice也写了一篇帖子explaining action hooks

相关问题