Custom permalink structure only for default posts

The solution is to reregister the default post type just after WordPress, and to add a rewrite slug. Also, the _builtin param needs to be set to false. add_action( ‘init’, ‘my_new_default_post_type’, 1 ); function my_new_default_post_type() { register_post_type( ‘post’, array( ‘labels’ => array( ‘name_admin_bar’ => _x( ‘Post’, ‘add new on admin bar’ ), ), ‘public’ => … Read more

How to add a new tab to page editor

I remembered that once I done this, yesterday I found where, but that code was… bad. So today I little improved it and I’m going to share. Before I want to explain what I do. First of all, there are 3 main things to do: Add the tab title beside the standard 2 Add something … Read more

Custom Field in Featured image for A particular post

Note that there are additional input arguments available for the admin_post_thumbnail_html filter callback, namely $post->ID and $thumbnail_id: /** * Filters the admin post thumbnail HTML markup to return. * * @since 2.9.0 * @since 3.5.0 Added the `$post_id` parameter. * @since 4.6.0 Added the `$thumbnail_id` parameter. * * @param string $content Admin post thumbnail HTML … Read more

Encryption of WordPress Posts

As far as I know what you ask is not really possible with WordPress (or any plain PHP app) alone. It is same dilemma as with database credentials in WP – if FTP is hacked then hacker gets database login/password from wp-config.php. It is impossible to protect those because WordPress (or any other PHP app … Read more

Delete the original big size image after upload and leave only 3 images crunched by media gallery

How about this: add_filter( ‘wp_generate_attachment_metadata’, ‘delete_fullsize_image’ ); function delete_fullsize_image( $metadata ) { $upload_dir = wp_upload_dir(); $full_image_path = trailingslashit( $upload_dir[‘basedir’] ) . $metadata[‘file’]; $deleted = unlink( $full_image_path ); return $metadata; } Not 100% sure everything will work ok without the main image, but it does the trick. You wont be able to regenerate the thumbnails / … Read more

Sort posts by popularity/page views

The WP Postviews plugin is one of the most used to record post views. Then you can sort by amount by; <?php if (function_exists(‘get_most_viewed’)): ?> <ul> <?php get_most_viewed(); ?> </ul> <?php endif; ?> Or pass in the variables to the URL: http://example.com/?v_sortby=views&amp;v_orderby=desc Or even run a custom query that sorts by the post_meta value.

Display the latest post from a category in a page

You can make use of WP_Query to call the lastest post from the category and display it. Have a look at the category parameters. By default, WP_Query uses post as the post type and orders post by post date, so we can exclude that from the query. If you need something else, you can just … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)