Change default upload images size for contributors

The default image size for inserting images is stored in the options table in image_default_size. You can change the default image size by updating the option: update_option( ‘image_default_size’, ‘large’ ); Role-dependent default image size To change the default image size for contributors only, you could hook into pre_option_[option] filter (which is fired directly after sanitizing … Read more

how to display a page before the home page

1) create one template page on your page-templates dir in landingpage.php with this code page-templates/landingpage.php <?php /** * Template Name: Landing page */ ?> <div id=”main-content” class=”main-content”> <div id=”primary” class=”content-area”> <div id=”content” class=”site-content” role=”main”> <?php // Start the Loop. while ( have_posts() ) : the_post(); the_content(); endwhile; ?> </div><!– #content –> </div><!– #primary –> </div><!– … Read more

Let users upload image(s) to the post from front end

wp_insert_attachment returns the resulting post_ID of attachment record created in posts table, so you will need to add these IDs (multiple) in the post meta table using update_post_meta as suggested in code below: $attchmentIds = array(); if ($_FILES) { foreach ($_FILES as $file => $array) { $newupload = insert_attachment($file,$pid); $attchmentIds[] = $newupload; } }; /*The … Read more

Deactivate a plugin on wp version

The problem is not version_compare, the problem is that register_activation_hook is just a shortcut for add_action( ‘activate_’ . $file, $function ); where $file is plugin_basename( __FILE__ ); and __FILE__ is your main plugin file absolute path. So, what your code does is to call dw_deactivate_theme_options() when the action ‘activate_’ . $plugin is fired. But this … Read more

current_page_item is missing inside wp_nav_menu

If you’re not actually using a custom nav menu, why are you not just outputting wp_page_menu() directly? Problem As-implemented, your walker will never be executed (or, more accurately, you can’t control whether or not it is executed), because you’re not passing ‘theme_location’ (correct usage) or ‘menu’ (sub-optimal usage) to the args array. Here’s how the … Read more

How can I alter this code to accept a slug as well as an ID?

The Codex essentially explains how to do this: if ( $category_to_check = get_term_by( ‘name’, ‘fruit’, ‘category’ )) post_is_in_descendant_category($category_to_check->term_id); https://codex.wordpress.org/Function_Reference/in_category#Testing_if_a_post_is_in_a_descendant_category Putting it all together in your function you would have: if ( ! function_exists( ‘post_is_in_descendant_category’ ) ) { function post_is_in_descendant_category( $cats, $_post = null ) { foreach ( (array) $cats as $cat ) { if (!absint($cat)) … Read more