Does hook have an effect on increasing the page load?

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>';

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

The 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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x