admin管理员组文章数量:1122833
I've created my custom posts. Data from the same is displayed in let's say single-custom-post.php.
Now to clean that file and to remove 100 lines of code, I want to make a new file (let's call it custom-header.php
) and then just echo or call that content.
Since I've built custom post as a plugin, ideally would be nice to call it if plugin is active, however I don't know how to finish this because one statement is if myplugin is active but then I would somehow add another statement - function, and here I am lost (below).
I could call it by if function exist, but then i am not sure how do I create that function.
What I did and it does work is this:
inside
custom-header.php
I've addedif ('custom_header_display') { ?> //my code } ?>
and then in single-custom-post.php
I replaced that 100 lines of code with
include (TEMPLATEPATH . '/inc/custom-header.php' );?>
So my problem is, I don't know is this a good way, and if it's not, what is it?
I've created my custom posts. Data from the same is displayed in let's say single-custom-post.php.
Now to clean that file and to remove 100 lines of code, I want to make a new file (let's call it custom-header.php
) and then just echo or call that content.
Since I've built custom post as a plugin, ideally would be nice to call it if plugin is active, however I don't know how to finish this because one statement is if myplugin is active but then I would somehow add another statement - function, and here I am lost (below).
I could call it by if function exist, but then i am not sure how do I create that function.
What I did and it does work is this:
inside
custom-header.php
I've addedif ('custom_header_display') { ?> //my code } ?>
and then in single-custom-post.php
I replaced that 100 lines of code with
include (TEMPLATEPATH . '/inc/custom-header.php' );?>
So my problem is, I don't know is this a good way, and if it's not, what is it?
Share Improve this question edited Mar 9, 2016 at 4:36 Pieter Goosen 55.4k23 gold badges115 silver badges209 bronze badges asked Mar 9, 2016 at 4:33 MaxMax 1294 silver badges14 bronze badges1 Answer
Reset to default 0You've got an issue with your code. This code will always return true
because you're passing a string to it.
if ('custom_header_display') { ?>
//my code
} ?>
You can instead use is_plugin_active()
to check if the plugin is activated.
Quoting the example from the Codex page, your code should be like:
<?php
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if ( is_plugin_active( 'plugin-directory/plugin-file.php' ) ) {
// include your file.
}
本文标签: How to display content If function existcondition true
版权声明:本文标题:How to display content If function existcondition true? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736281667a1926391.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论