Separate WordPress themes for each category page

I think what would work best for your case is making use of the WordPress template hierarchy. You can actually just create a custom template file in your theme folder named category-{slug}.php to get a custom look for that category. Example: If your category was ‘Dogs’ and the slug you set for it was ‘dog’, … Read more

remove tags from posts in php

Below is code that works: function untag_posts($post_ids, $tags) { global $wpdb; if(! is_array($post_ids) ) { $post_ids = array($post_ids); } $in_post_ids = implode(“‘,'”, $post_ids); if(! is_array($tags) ) { $tags = array($tags); } $in_tag_names = “‘” . implode(“‘,'”, $tags) . “‘”; $query = “SELECT tt.term_taxonomy_id ” . ” from $wpdb->terms as t ” . ” JOIN $wpdb->term_taxonomy … Read more

How to target with css, admin elements according to user role level?

The admin_body_class filter lets you add classes to the body tag. This function will add all roles as classes in the form role-$role, for example role-administrator, to the body tag: function wpa66834_role_admin_body_class( $classes ) { global $current_user; foreach( $current_user->roles as $role ) $classes .= ‘ role-‘ . $role; return trim( $classes ); } add_filter( ‘admin_body_class’, … Read more

How to use update and delete query in wordpress

About UPDATE+INSERT: I have made a function for myself, and might help you too, i.e. : UPDATE_OR_INSERT(‘wp_users’, array(‘gender’=>’female’), array(‘name’=>’Monika’) ); that will UPDATE A VALUE in column (where name=monika), but in case that value doesnt exists, then it creates a new record in DB. Why this is necessary? because As far as i know, there … Read more

Check if a menu is empty?

wp_nav_menu has the argument fallback_cb, which is the function called if a menu doesn’t exist. This is set to wp_page_menu by default, which is why you see a list of pages if the menu doesn’t exist. If you explicitly set that to false, then nothing will be output if the menu doesn’t exist. EDIT- Given … Read more

Switching wp_get_sites to get_sites

This is a great question. First of all, the comparison operator (?:) you’re referring to is called a ternary operator. It’s great for simple if/then blocks. It took me a while to get used to them, but now I use them all the time. You can take a simple expression and return a value depending … Read more

How Attackers write script into my php files?

Hi @Syom: Often hackers get access because you use the name “admin” for your administrator and you have an easy to hack password. Or because you don’t update your software and they leverage some of the security holes that have been found and patched. Here’s a set of slides that go indepth to explaining how … Read more

How to register images uploaded via FTP in media library?

It’s because you’re not registering them as a media type. Every upload is a WordPress post of the attachment type. To start, it would be something like this: $file_name=”Some Name”; $file_path=”/path/to/uploads/2012/08/04/newfile.jpg”; $file_url=”http://url/to/uploads/2012/08/04/newfile.jpg”; $wp_filetype = wp_check_filetype($file, null); $attachment = array( ‘guid’ => $file_url, ‘post_mime_type’ => $wp_filetype[‘type’], ‘post_title’ => $file_name, ‘post_status’ => ‘inherit’, ‘post_date’ => date(‘Y-m-d H:i:s’) … Read more