Hard Code Pages into a Theme for a Network (multisite) Installation

Hook into wpmu_new_blog and create your pages: add_action(‘wpmu_new_blog’, ‘create_my_pages’, 10, 2); function create_my_pages($blog_id, $user_id){ switch_to_blog($blog_id); // not really need, new blogs shouldn’t have any content if(get_page_by_title(‘About this Network’)) return; // create each page $page_id = wp_insert_post(array( ‘post_title’ => ‘About this Network’, ‘post_name’ => ‘about-this-network’, ‘post_content’ => ‘Co za asy…’, ‘post_status’ => ‘publish’, ‘post_author’ => $user_id, … Read more

get_template_directory vs get_stylesheet_directory

Why don’t theme developers just use get_stylesheet_directory if it would work for the parent or child theme? The answer is not complicated: “Because you may not want it to work for either the parent or a child theme.” You choose the function that fits the situation. For example, you have a set of files in … Read more

add_image_size is scaling, even though crop is set to true

from your question i under that you want fixed size cropped images when you upload image, why don’t you use wp_get_image_editor. I used it in my project where i wanted cropped images of fixed size so i did this code. $path = $newPath[‘basedir’].’/newImgas/’; $cropfile = uniqid() . ‘.png’; $cropfilename = $path.$cropfile; $cropImage = home_url(). ‘/wp-content/uploads/newImgas/’.$cropfile; … Read more

How to solve “Warning: Use of undefined constant” when overriding a parent theme function in the child theme?

Child themes are loaded before the parent theme. That’s why you’re able to replace functions that are wrapped in function_exists(). When themes use function_exists() they are taking advantage of the fact that child themes are loaded first to let the child theme define a function with the same name without throwing an error. The reason … Read more

add generated stylesheet from parent theme after child-themes style.css

Absolutely! Into functions.php, like you said. I’ll call it cache_busting_styles because I like how it sounds. First, you set up the style via wp_enqueue_style, then call it during the action hook wp_print_styles, Also, you’ll want to set up a variable and pass it in there as the version number as well: function cache_busting_styles() { //however … Read more

Removing custom meta box added in parent theme

Note: This is the merged version between my and @toscho answers. Explanation (by @toscho) Use add_meta_boxes_page as action hook. You can find the hook in wp-admin/edit-form-advanced.php and it displays as: do_action(‘add_meta_boxes_’ . $post_type, $post); Solution(s) Try the following action, which is inside register_post_type() as well. function wpse59607_remove_meta_box( $callback ) { remove_meta_box( ‘id-of-meta-box’ , ‘page’ , … Read more

is there a simple way to list every templates / php files used to generate a specific page?

WordPress does not really track what theme files are loaded beyond some basic things (for example $template global holds main template file). You can use PHP’s native get_included_files() to list all PHP source files loaded during request and narrow it down to your theme. Note that for more complex themes this will have not only … Read more