How do I add settings to the Background Options Page?

The page content for custom backgrounds is created in wp-admin/custom-background.php. There is no action available where the fields are printed. To add new fields we have to print JavaScript into the page footer. The action is ‘admin_footer-appearance_page_custom-background’. To save those field values we have to hook into ‘load-appearance_page_custom-background’. The following example adds a new option … Read more

WordPress Themes and PHP unit

When it comes to unit testing themes, it’s a small jungle. I read on Make WordPress Core that things are changing (http://make.wordpress.org/core/2013/08/06/a-new-frontier-for-core-development/). I searched for blogs linking to that specific post in hope to find some useful. Found this: http://ben.lobaugh.net/blog/84669/how-to-add-unit-testing-and-continuous-integration-to-your-wordpress-plugin that looks promising. Note that it focuses on plugin testing, but useful for theme unit … Read more

Should `get_template_directory_uri()` be escaped?

In that function we find a hook: return apply_filters( ‘template_directory_uri’, $template_dir_uri, $template, $theme_root_uri ); So, yes, the URI can be changed by plugins, and you should escape its returned value. The same principle applies to all WordPress URI functions, like get_home_url(), get_site_url() and so on. Keep in mind that there are not only good plugin … Read more

Form to Add Posts to Custom Post Type

posting from the front-end is a matter of displaying a form and processing it: form: <!– New Post Form –> <div id=”postbox”> <form id=”new_post” name=”new_post” method=”post” action=””> <!– post name –> <p><label for=”title”>Title</label><br /> <input type=”text” id=”title” value=”” tabindex=”1″ size=”20″ name=”title” /> </p> <!– post Category –> <p><label for=”Category”>Category:</label><br /> <p><?php wp_dropdown_categories( ‘show_option_none=Category&tab_index=4&taxonomy=category’ ); ?></p> … Read more

With WordPress themes, where do I store the images and files relatively?

Let me answer your question with a question: Are these images part of your template or for general purpose? The WordPress theme “Responsive” has images files all over its theme folder. The theme should be at yoursite.com/wp-content/themes/responsive. In that theme folder there are a few folders with images: The obvious “images”, also “icons” and “includes/images”. … Read more

Display random categories on the front page (Finding and Editing Theme Functions)

The real question here is: How do I find “TheirCode” which is responsible for this selection using tools such as firefox dev bar and the actual source? If you are referring to the HTML output/source, then for example on the official Storefront theme demo site, just right-click on the “Product Categories” heading or section and … Read more

Bestway To Define Theme and Plugin path and url

Do not use constants for that. Do not use global constants at all. There are two types of constants: class/interface constants and global constants. Constants in classes or interfaces are fine and sometimes useful. An overly simplistic example: interface Requirements { const MIN_PHP_VERSION = 5.4; public function php_is_good(); } class Theme_Requirements implements Requirements { public … Read more