0

我创建了一个以custom_page.phpwordpress 命名的自定义页面并将其用作页面模板。

我想创建自己的函数,并且只针对我的custom_page.php. 此功能将作为插件安装。

我应该使用什么样的 WP HOOKS,例如我在下面有这个代码

function your_function() {
    if ( is_page_template('custom_page.php') ) {
     echo '<p>This is inserted at the bottom</p>';
     {

}
add_action('wp_footer', 'your_function');

我只想在我的custom_page.php页脚区域中执行此代码。

[编辑]

4

1 回答 1

0

您可以将这些钩子用于页面模板。 http://adambrown.info/p/wp_hooks/hook/page_template

或者可能是这样的......

add_filter( 'page_template', 'check_the_template' );
function check_the_template( $template ) {
    if( 'custom_page.php' == basename( $template ) ) {
        // do some things here by calling functions, hooks etc..
    }
    return $template;
}

如果您只想回显“Hello World”:

add_filter( 'page_template', 'check_the_template' );
function check_the_template( $template ) {
    if( 'pagetemplete.php' == basename( $template ) ) {
        add_action( 'the_content', 'echofunction' );
    }
    return $template;
}
function echofunction() {
    echo "Hello World";
}
于 2013-09-13T07:57:24.937 回答