Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用wordpress中的插件功能定位自定义页面_Wordpress_Customization - Fatal编程技术网

使用wordpress中的插件功能定位自定义页面

使用wordpress中的插件功能定位自定义页面,wordpress,customization,Wordpress,Customization,我在wordpress中创建了一个名为custom_page.php的自定义页面,并将其用作页面模板 我想创建自己的函数,只针对我的自定义页面.php。此功能将作为插件安装 我应该使用什么样的WP钩子,例如下面的代码 function your_function() { if ( is_page_template('custom_page.php') ) { echo '<p>This is inserted at the bottom</p>';

我在wordpress中创建了一个名为
custom_page.php
的自定义页面,并将其用作页面模板

我想创建自己的函数,只针对我的
自定义页面.php
。此功能将作为插件安装

我应该使用什么样的WP钩子,例如下面的代码

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');
函数你的函数(){
if(是页面模板('custom\u page.php')){
echo'这是在底部插入的;
{
}
添加_操作(“wp_页脚”、“您的_函数”);
我只想在我的custom_page.php页脚区域执行这段代码


[编辑]

您可以将这些挂钩用于页面模板。

或者可能是这样的

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";
}