tags:

views:

18

answers:

1

When I'm building a Wordpress theme I usually comment the code which generates the element I want to remove, but I was wondering if professional Wordpress theme developers do it this way. Does Wordpress have filters and declaration which remove elements?

For instance removing elements in the contact form (e.g Website field). Date and links (e.g posted_in and posted_on) in posts (single.php) etc...

I know 3 ways so far:

  • Via CSS: giving the element display: none;
  • Commenting (<!-- -->, //) or deleting the code
  • Using some php filters or declarations

Which one is the most efficient and easy way (the one that professional Wordpress developers use?)

+1  A: 

It depends on where the code is being generated from. If it's in your theme files, then the best way is to comment or delete the code. This way, no processing is required to display the element and then hide it with CSS or remove it with a filter.

If the element is coming from the WordPress core files, then you should use a filter or remove_action in your theme's functions.php. The reason for this is twofold:

  1. By not modifying the core files, you don't run any risk of breaking your site if you upgrade WordPress.
  2. You keep the size of your generated pages smaller and therefore quicker to load.

Using CSS to hide should only be a last resort since the user still has to download the hidden markup and anyone browsing without CSS or using a screen reader will still encounter all those elements you don't want on your site.

Pat