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:

Adding Widget form fields dynamically

Posted by Prem Tiwari | Updated on | WordPress


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 | WordPress


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 | WordPress


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 | WordPress


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 | WordPress


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 | WordPress


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 …

How does WordPress handle permalink?

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 …

Is there a is_user_logged_in() for multisite?

Posted by Prem Tiwari | Updated on | WordPress


Is there a is_user_logged_in() for multisite? The way users work in a multisite scenario is that there is a single pool of users, who are then associated with blogs. So, logged in status is common …