How do I render all posts of the same category in same layout?

I believe you are talking about single post pages. The template hierarchy does not make provision for single templates according to the category a post belongs to, so single-{$category}.php does not exist. To make single-{$category}.php work, we can make use of the single_template filter add_filter( ‘single_template’, function ( $template ) { global $post; // Check … Read more

Enabling post thumbnails for custom post type

You are most probably using add_theme_support() in the wrong context (hook). Because you are registering the post type yourself, all you need to do is to add support for thumbnails in the supports array when you pass your your arguments to register_post_type() supports (array/boolean) (optional) An alias for calling add_post_type_support() directly. As of 3.5, boolean … Read more

Search for posts based on their url in the admin?

Here’s one way to support searching for post slugs in the backend. Let’s invoke this kind of search by the slug: string in the search term. Example To search for slugs that end in -2 we want to be able to search for: slug:*-2 where * is the wildcard. Demo Plugin Here’s a demo plugin … Read more

Manually removing revision post types

IF you want, you can disable revisions in first place (No need to run CRON then) To disable them go to wp-config.php and add this line: define(‘WP_POST_REVISIONS’, false ); Or to limit to 10 revisions define(‘WP_POST_REVISIONS’, 10); And to delete all current revisions you can run this SQL query: DELETE FROM wp_posts WHERE post_type = … Read more

Two posts are loaded instead of one?

The core of the problem is that you set cookies when the content is being accessed, not when it is read. Browsers can try to prefetch content, and your description sound like the browser is prefecthing the “next” link found in the header. From experience, you should avoid setting cookies on the server and prefer … Read more

disable column on post and user list

You can use the manage_{$screen->id}_columns hooks for this. To manage user columns we can use manage_users_columns which is passed an array of columns and whatever we don’t want we can unset(). /** * Manage User Admin Display Table Columns * * @param Array $columns * [cb] => <input type=”checkbox” /> * [username] => Username * … Read more

Different template for posts of all subcategories of category

You can check if current category is a child of blog category with cat_is_ancestor_of() function or term_is_ancestor_of(), or maybe better, use in_category(), as you are currently doing, but checking child categories as well. add_filter( ‘single_template’, ‘get_custom_cat_template’ ) ; function get_custom_cat_template( $single_template ) { // You want to filter only template for single posts of default … Read more

Custom excerpt length filter doesn’t work

For anyone wondering, as custom excerpts don’t get trimmed by the excerpt_length filter hook, try adding this filter: function trim_custom_excerpt($excerpt) { if (has_excerpt()) { $excerpt = wp_trim_words(get_the_excerpt(), apply_filters(“excerpt_length”, 55)); } return $excerpt; } add_filter(“the_excerpt”, “trim_custom_excerpt”, 999);