[wp-hackers] Force plugin to add code only where really needed

Eric Mann eric at eam.me
Tue Feb 22 15:20:29 UTC 2011

The practice you're referring to, where only a few developers use the
appropriate functions and hooks, is a result of *bad code*.  WordPress has
all the hooks in place for developers to add their scripts and styles only
where they should (rather than on every page load), but a lot of us are lazy
and don't do things the right way the first time, much to the detriment of
our users' site performance.

The easiest way to hook scripts or styles to a specific page is with

if( is_page('x')) { ?>
<?php }

You can do the same for `is_home()` and `is_frontpage()` and `is_single()`

The problem is that you can't dictate coding practices in core.  We expose
all the hooks, filters, etc necessary for developers to use clean code and
build quality systems, but there's no way to force them to.

On Tue, Feb 22, 2011 at 7:08 AM, mailapera <mailapera at gmail.com> wrote:

> Hi,
> is there a way to do it? Almost all plugins add a bunch of css,
> jquery, JS, php, ajax, meta tags all over the places in the code, even
> if you need a plugin only on one single post or page. This slows down
> performance and dirties the code quite a lot. Is there a way to force
> a plugin, use a simple "if" statement, to detect where it is
> absolutely needed and only output code on that page? I see that some
> plugin developers do it, could this be implemente in the core? Thanks
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

More information about the wp-hackers mailing list