Catchable fatal error on 3.6 update

image_resize (deprecated) is returning an error object so really, the problem is here: $new_img_path = image_resize( $file_path, $width, $height, $crop ); Something is wrong with that line and you are not checking whether the return value is an error object or a string before trying to use the return value as a string. You did … Read more

Creating sub-categories via php

You can use the wp_insert_term() function to achive this. First create the parent category, then create a child category. $parent = wp_insert_term( ‘Parent Category’, // category name ‘category’, // taxonomy array( ‘description’ => ‘Category description’, // optional ‘slug’ => ‘parent-category’, // optional ) ); wp_insert_term( ‘Child Category’, // category name ‘category’, // taxonomy array( ‘description’ … Read more

Add filter multiple times using only one master function

Use a use statement: add_filter( ‘single_template’, function ( $template ) use ( $name ) { Or just pass all templates at once, and create just one function: add_filter( ‘single_template’, function ( $file ) use ( $templates ) { global $post; if ( in_array ( $post->post_type, $templates ) ) return __DIR__ . “/{$post->post_type}.php”; return $file; });

Get my site session in wordpress?

WordPress doesn’t use PHP session ($_SESSION). If you want to use it you need to do at your own. For example: add_action(‘init’, ‘wpse_session_start’, 1); function wpse_session_start() { if(!session_id()) { session_start(); } } But, if you want is to get the user id of the current user, you can use get_current_user_id(): <?php $user_ID = get_current_user_id(); ?>

Conditional Javascript based on WP Version

You can do this with the function get_bloginfo(). There is a special paramater called version that retrieves the wordpress version from the $wp_version variable set in wp-includes/version.php. So you could do something like this function register_jquery_wp_version() { global $wp_version; if ( $wp_version >= 3.8 ) { // register and enqueue jquery A }elseif( $wp_version >= … Read more

How can I call specific function if requested URL is not found?

Simply use template_redirect filter to perform check on request you get in wordpress. add_filter(‘template_redirect’, ‘my_404_override’ ); function my_404_override() { global $wp_query; if (!$wp_query->post) { // Check if any post is found. If not its 404. status_header( 200 ); $wp_query->is_404=false; // Create post object $my_post = array( ‘post_title’ => ‘My post’, ‘post_content’ => ‘This is my … Read more