admin管理员组文章数量:1313073
I have a personal website which uses WordPress. for same changes on the theme, I can add manually codes on single.php. Or I can write a hook for it. for example, I want to add content on a specific single.php line.
// I made a action
function after_p(){
do_action('after_p');
}
and then put it on single.php
<?php after_p();?>
then I add some line and PHP files with add action on function.php
// Download Box
if (!function_exists('downloadbox')) :
{
function downloadbox()
{
if (function_exists('get_field'){
include('downloadbox.php');
}
}
}
endif;
add_action( 'after_p', 'tc_downloadbox' );
// adv
if (!function_exists('my_adv')) :
{
function my_adv()
{
echo '<div id="java-script-advs"></div>';
}
}
endif;
add_action( 'after_p', 'my_adv' );
As you guess I am a beginner I have a doubt this way is current?
I mean does use the unnecessary hook have effects on page loading?
because on my case I can simply add include('downloadbox.php')
on single.php(on the line what I want). at the same for echo '<div id="java-script-advs"></div>';
I have a personal website which uses WordPress. for same changes on the theme, I can add manually codes on single.php. Or I can write a hook for it. for example, I want to add content on a specific single.php line.
// I made a action
function after_p(){
do_action('after_p');
}
and then put it on single.php
<?php after_p();?>
then I add some line and PHP files with add action on function.php
// Download Box
if (!function_exists('downloadbox')) :
{
function downloadbox()
{
if (function_exists('get_field'){
include('downloadbox.php');
}
}
}
endif;
add_action( 'after_p', 'tc_downloadbox' );
// adv
if (!function_exists('my_adv')) :
{
function my_adv()
{
echo '<div id="java-script-advs"></div>';
}
}
endif;
add_action( 'after_p', 'my_adv' );
As you guess I am a beginner I have a doubt this way is current?
I mean does use the unnecessary hook have effects on page loading?
because on my case I can simply add include('downloadbox.php')
on single.php(on the line what I want). at the same for echo '<div id="java-script-advs"></div>';
1 Answer
Reset to default 0The cost of those hooks themselves is negligble and statistically insignificant. It would take great effort to measure such a change in performance, and would not take up more than a millionth of the total runtime. Unused hooks are not a performance concern.
The real concern here is that unnecessary complexity has been added that will show in the future as technical debt. I also notice you've wrapped all your functions in {}
then again in a function exists check, both of which aren't necessary
本文标签: functionsDoes hook have an effect on increasing the page load
版权声明:本文标题:functions - Does hook have an effect on increasing the page load? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741928113a2405414.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
do_action()
call with a direct function call todj_after_p()
that called for the include file and echo'd the .java-script-advs div. – jdm2112 Commented Dec 3, 2020 at 3:10after_p()
which runsdo_action('after_p')
, you could just do<?php do_action('after_p');?>
. – Gerard Reches Commented Jan 7, 2024 at 3:30