All Questions (5,597 questions)



Custom post type with a forced fixed aspect ratio image crop

Posted by Prem Tiwari | Updated on

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

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

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

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

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

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

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

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

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:

Adding Widget form fields dynamically

Posted by Prem Tiwari | Updated on

This is an example of a dynamic widget that renders two fields (image-id and url). if you enter an image-id and press “update”, two new fields are added. I build it to create a slick …

Admin very slow edit page caused by core meta query

Posted by Prem Tiwari | Updated on

If you want to test your custom SQL to see how it affects the loading time, you can try this query swapping:

Using classes instead of global functions in functions.php

Posted by Prem Tiwari | Updated on

Using a class for encapsulation is a very common approach by a number of developers for plugins. I do this, and I do find it cleaner. But for plugins. Themes are more procedural by nature. …

How can you set maximum width for original images?

Posted by Prem Tiwari | Updated on

How can you set maximum width for original images. I was able to solve it using the following code:

How to use wpLink without editor?

Posted by Prem Tiwari | Updated on

There is not ethical way of doing this. But still there is a way to do this. WordPress wrote wpLink script keeping in mind that editor is there but still WordPress handle when editor is …

Symbolic Links on dev box with plugins and stylesheets

Posted by Prem Tiwari | Updated on

Symbolic Links on dev box with plugins and stylesheets. As you can see, the plugin URL is correct except for the real path stuck in the middle. We can filter the function responsible for generating …