PHP array_chunk() example

Posted by Prem Tiwari | Updated on | in PHP Documentation.


PHP array_chunk() — Split an array into chunks. Chunks an array into arrays with size elements. The last chunk may contain less than size elements. Syntax: Returns a multidimensional numerically indexed array, starting with zero, …

PHP array_shift() example

Posted by Prem Tiwari | Updated on | in PHP Documentation.


array_shift — Shift an element off the beginning of array. array_shift() shifts the first value of the array off and returns it, shortening the array by one element and moving everything down. All numerical array …

PHP array_unshift() example

Posted by Prem Tiwari | Updated on | in PHP Documentation.


array_unshift — Prepend one or more elements to the beginning of an array. array_unshift() prepends passed elements to the front of the array. Note that the list of elements is prepended as a whole, so …

How to control accept encoding on HTTP API requests?

Posted by Prem Tiwari | Updated on | WordPress


Quite an edge case, but the accepted encoding types should be filterable nonetheless. I can see a few situations where fine, granular control over this header would be useful (as in adding an API that …

Open a Thickbox with content trough AJAX

Posted by Prem Tiwari | Updated on | WordPress


The second parameter for tb_show is the URL, so you’ll want to use something like..

How does WordPress handle permalinks?

Posted by Prem Tiwari | Updated on | WordPress


The redirect_canonical function in /wp-includes/canonical.php is called on any given URL and will attempt to best-guess the URL the user wanted, and redirect them to there, when a URL does not exist. It has a …

Custom post type with a forced fixed aspect ratio image crop

Posted by Prem Tiwari | Updated on | WordPress


You will have to add support for thumbnails in your functions.php/plugin-file.php From here you can modify this output in your loop to work for your needs:

Generate Thumbnails only for Featured Images

Posted by Prem Tiwari | Updated on | WordPress


This function will generate an image by temporarily registering an image size, generating the image (if necessary) and the removing the size so new images will not be created in that size.

How to conditionally enqueue a stylesheet only for a certain page?

Posted by Prem Tiwari | Updated on | WordPress


I copy pasted your code into my dev environment, changed nothing but the page name, and it works just fine. Are you sure that it’s not being enqueued and you just have it pointed wrong …

current_shortcode() detect currently used shortcode

Posted by Prem Tiwari | Updated on | WordPress


current_shortcode() detect currently used shortcode. I made my catch all handler accept a third argument, which is the shortcode name:

How can I display a menu on certain pages only?

Posted by Prem Tiwari | Updated on | WordPress


That’s a nice option, but I agree with sri, right now it really depends on your theme. You can do a work-around through is_page(). You need to write something like this on your page.php theme …

Is there any action hook for validating a custom field before publishing the post?

Posted by Prem Tiwari | Updated on | WordPress


At the beginning of wp_insert_post, the function that saves/updates a post, there is a filter called wp_insert_post_empty_content. By default this filter checks whether the title, editor, and excerpt fields are all empty, in which case the save …

Use template_include with custom post types

Posted by Prem Tiwari | Updated on | WordPress


I am not sure if this will work for you but it is worth a shot. I use this all the time for my custom post types when they require a special template.

Allow user to select a theme to install when they signup

Posted by Prem Tiwari | Updated on | WordPress


If still relevant, maybe this could help others looking for similar solutions

How to implement WordPress plugin update that modifies the database?

Posted by Prem Tiwari | Updated on | WordPress


You should be familiar with already, as you should be using it to create the table. On your install hook you should have something like: