Using the Rewrite API to Construct a RESTful URL

Posted by Prem Tiwari | Updated on | WordPress


I would separate the logic into three parts: a controller select a model and a view, a model to handle the endpoint and one or more views to return some useful data or error messages. …

Change login error messages

Posted by Prem Tiwari | Updated on | WordPress


You can do that using login_errors filter hook and here is how:

Customizing a WordPress theme without changing it?

Posted by Prem Tiwari | Updated on | WordPress


While you can’t modify it without changing it, you can isolate the parts you change by creating a Child Theme. In summary: Create a theme directory on peer with your “parent” theme, Create a style.css file in …

How do I get the $handle for all enqueued scripts?

Posted by Prem Tiwari | Updated on | WordPress


The $wp_scripts global holds all the script data:

WP Cron Doesn’t Execute When Time Elapses

Posted by Prem Tiwari | Updated on | WordPress


Firstly, define your custom cron job schedules.

Creating a wp_editor instance with custom tinyMCE buttons

Posted by Prem Tiwari | Updated on | WordPress


Here’s what you might be looking for for instances 2 and 3 (for instance 1 you can leave the settings empty to get the default set of buttons): Instance 2: Instance 3 (showing each of …

WordPress Admin Page Redirect

Posted by Prem Tiwari | Updated on | WordPress


Use the below example code in your functions.php file to add admin page redirect in your WordPress site.

How to override existing plugin action with new action

Posted by Prem Tiwari | Updated on | WordPress


You can use the remove_action() function, like this: It’s important to note that if the old_action was added with a priority parameter, you must add that to the remove_action call, otherwise it will fail to …

I want to enqueue a .js file to my child theme

Posted by Prem Tiwari | Updated on | WordPress


Here’s a working example: Or like this which apparently loads faster:

Attaching taxonomy data to post with wp_insert_post

Posted by Prem Tiwari | Updated on | WordPress


Use wp_set_object_terms after you have the post id for each taxonomy:

Disable plugin, plugin action via theme

Posted by Prem Tiwari | Updated on | WordPress


Here is my solution, create a plugin that can disable other plugins like so:

Most efficient way to add javascript file to specific post and/or pages?

Posted by Prem Tiwari | Updated on | WordPress


I think the best balance between efficiency, and using proper wordpress methods for adding javascript would be adding something along these lines to your themes functions.php file. For Example: functions.php:

How to get post author id outside loop in WordPress

Posted by Prem Tiwari | Updated on | WordPress


With this function I was able to display post author e-mail in post edit screen. Still don’t know how to make it work with custom meta field but I think Im closer now.

How to set SMTP programmatically

Posted by Prem Tiwari | Updated on | WordPress


To achieve it we need to get access to $phpmailer variable. And here we come to phpmailer_init action which is called before sending an email. So we can do what we need by writing our …

How to add a data attribute to a WordPress menu item

Posted by Prem Tiwari | Updated on | WordPress


Specifically editing the code you provided in the original question: