使用wordpress中的插件功能定位自定义页面
我在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>';
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";
}