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

esc_attr() right way and use

No you don’t need esc_attr() function to print out fixed static text. You only need it to print out dynamic or generated text, so that if the attributes have any special characters that may break your HTML, esc_attr will escape that properly. In your particular case, you can just write: echo ‘<label><input type=”checkbox” id=”custom_header” name=”custom_header” … Read more

Shared functionality in plugins and themes

Actions & Filters The imho best way is to use an action to bring plugin functions into themes. Example #1 Here’s a little plugin to test this. <?php /** Plugin Name: (#68117) Print Hello! */ function wpse68117_print_hello() { echo “Hello World!”; } add_action( ‘wpse68117_say’, ‘wpse68117_print_hello’ ); Inside the theme: <?php /** Template Name: Test »Print … Read more

Undefined offset: 0 in > […] /wp-includes/capabilities.php on line 1067

You have found a bug in Genesis. Your Xdebug stack trace fingers the culprit as the genesis_save_custom_fields() function which calls current_user_can() with a singular capability (edit_post and edit_page) which also requires an additional argument, in this case the post ID which is missing. current_user_can() calls has_cap() which calls map_meta_cap() which does a switch statement on … 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

what the best way to include images from the template’s images folder?

The easiest and simplest way to do it is define a unique variable in your theme’s functions.php file. Such as: <?php $theme_name_images = get_bloginfo(‘stylesheet_directory’) . ‘/images/’; ?> No need for classes as a previous answer suggested. EDIT: It should be get_bloginfo, instead of bloginfo(), as Viper007Bond kindly pointed out.

How can I version the main CSS file?

Style.css is required for your WordPress theme. That’s where WordPress gets the theme name and meta information for the Appearance >> Themes menu from. That said, you don’t actually have to use style.css in your theme at all. I know of several readily available themes that don’t use it, and I only use it in … Read more