Query for user roles

You can check for specific user role using following code – if (is_user_logged_in() && current_user_can(‘administrator’)) {} The function current_user_can() takes role name as parameter. For more info – https://codex.wordpress.org/Function_Reference/current_user_can/

How to modify get_the_excerpt() when post-format equals ‘quote’?

While writing the question in SE I already found the solution: add_filter( ‘get_the_excerpt’, ‘get_custom_the_excerpt’ ); function get_custom_the_excerpt($excerpt) { $post = get_post(); $format = get_post_format( $post ); // modify excerpt if it is a quote, for example set title as author if ($format == ‘quote’) { $output=”<q>”. $excerpt. ‘</q> <p class=”quoted”>’.get_the_title().'</p>’; } // return excerpt without … Read more

Use add_action within template

There is no limitation to using add_action(), except that core must have it loaded already. Practically this means pretty much anywhere, but wp-config.php. While it is possible to do it in template, it’s not a common practice because of: Timing issues (your template part might be loaded after the hooks you need). Code base clarity … Read more

How to use wp_list_categories with plugin category?

I just tried the plugin you mentioned. You need to use following code to get categories from that plugin: wp_list_categories(‘title_li=Carousel%20Categories&orderby=name&taxonomy=carousel_category&hide_empty=0′); Notice the ‘taxonomy’ parameter in the querystring, it has the value of custom taxonomy registered by plugin. The default value is ‘category’ which is WordPress default category. For any other custom taxonomy you need to … Read more

remove/hide wp-editor

I believe the helper you’re looking for (assuming we’re not dealing with a custom post type) is: <?php remove_post_type_support(‘page’, ‘editor’); ?> When dealing with a custom post type you can exclude ‘editor’ from the ‘supports’ parameter to initialize the post type without the editor window. Finally, if you are trying to disable the editor only … Read more

wp_usermeta – Read from database, but save function broken

You have not provided the whole code so don’t understand where you are wrong, this script is working fine for me. add_action( ‘personal_options_update’, ‘save_extra_profile_fields’ ); add_action( ‘edit_user_profile_update’, ‘save_extra_profile_fields’ ); function save_extra_profile_fields( $user_id ) { if ( current_user_can(‘edit_user’,$user_id) ) update_user_meta($user_id, ‘uidnumber’, sanitize_text_field($_POST[‘uidnumber’])); } add_action(‘show_user_profile’, ‘show_extra_profile_fields’); add_action(‘edit_user_profile’, ‘show_extra_profile_fields’); function show_extra_profile_fields( $user ) { ?> <p class=”form-row form-row-wide”> … Read more