Override widget in function WordPress

You are getting this error because your class ass no method named widget which is a must to properly use the widgets api. Meaning that each class/widget that extends the WP_Widget class must have a method named widget which is responsible for the actual widget display. So consider this structure as a widget class skeleton: … Read more

Change template on the fly based on post parent selection

This is how you do it… function update_post_template($post_id, $post){ //set $post_parent_id however you wish if ($post->post_parent == $post_parent_id) { //unhook save_post action to avoid infinite loop remove_action(‘save_post’, ‘update_post_template’); //change template update_post_meta( $post_id, ‘_wp_page_template’, ‘custom_template.php’ ); //re-hook save_post action add_action(‘save_post’, ‘update_post_template’); } } add_action(‘save_post’, ‘update_post_template’, 10, 2); Notes: To explain what is happening, first we hook … Read more

Help with WP gallery function, wrap gallery in div

I just added a div to your function see comment in code: <?php add_filter( ‘post_gallery’, ‘my_post_gallery’, 10, 2 ); function my_post_gallery( $output, $attr ) { global $post, $wp_locale; static $instance = 0; $instance ++; if ( isset( $attr[‘orderby’] ) ) { $attr[‘orderby’] = sanitize_sql_orderby( $attr[‘orderby’] ); if( !$attr[‘orderby’] ) { unset( $attr[‘orderby’] ); } } … Read more

Get_template_part inside a folder

I assume you have a file in templates/masterhead-templatename.php, and it works, it is ok. Correct me if I am wrong, you want to locate this file like this masterhead-templatename.php, basically one folder up, but this wordpress function does not work like this. If the file exists in the root’s theme folder, it does not recognize … Read more