Do something after sending email

Posted by Prem Tiwari | Updated on | WordPress


Do something after sending email. I did some digging into the PHPMailer class and found that it supports a custom action. Here’s how the callback is activated with the doCallback() method in the class. There’s also a PHPMailer test on GitHub using this feature …

Understanding add_rewrite_rule

Posted by Prem Tiwari | Updated on | WordPress


Understanding add_rewrite_rule. A basic rule that would work for your example: This takes whatever comes after foo/ and sets that as pagename for the query, and then param gets the static value foo. If you …

What is the Advanced $context in add_meta_box?

Posted by Prem Tiwari | Updated on | WordPress


What is the Advanced $context in add_meta_box? The difference between normal and advanced is that normal will be placed on the page before advanced. For example the following will display “One” before “Two” If you …

Redirect Main Site to Subsite in Multisite WordPress

Posted by Prem Tiwari | Updated on | WordPress


Redirect Main Site to Subsite in Multisite WordPress. You can use the parse_request action to accomplish this. Simply enable this plugin on your primary blog. Place the following code in a .php file and upload …

Setting WPLANG from a plugin

Posted by Prem Tiwari | Updated on | WordPress


Setting WPLANG from a plugin. In wp-includes/l10n.php you will find the function get_locale(). It offers a filter; you can set the language and ignore the constant: To change it per plugin use the filter ‘locale’. …

Move excerpt meta box to above content editor

Posted by Prem Tiwari | Updated on | WordPress


Move excerpt meta box to above content editor. It’s simple, just unregister postexcerpt box first then add another one on the top. Here is my code:

Change CSS/formatting on specific page, but not pages in general?

Posted by Prem Tiwari | Updated on | WordPress


After creating the specific CSS you need to format the page how you like, you could: Create a custom page template with the CSS and assign the template this page. Create a page-{slug}.php file with the CSS, …

What action should I hook into when adding roles and capabilities?

Posted by Prem Tiwari | Updated on | WordPress


When adding a role and capabilities you only need to run the code once since the roles and capabilities are saved to the database when using add_role or ->add_cap functions so just like Andy said …

How to check if a slug exists?

Posted by Prem Tiwari | Updated on | WordPress


How to check if a slug exists? This is what you’re looking for, tested and I use it on my own sites: You can then use it like this:

Preserving theme settings in child theme

Posted by Prem Tiwari | Updated on | WordPress


You could do something like what Genesis child themes include to save default theme settings when activating and switching themes: Clearly you would need to modify this code to work with your themes functionality.

after_setup_theme always runs

Posted by Prem Tiwari | Updated on | WordPress


after_setup_theme always runs SOLUTION: after_switch_theme does exactly what I intended here. It fires after the theme is switched TO your theme. One of the solutions mentioned below uses switch_theme. This does not have the desired …

How to echo the_excerpt without the P tag wrapper?

Posted by Prem Tiwari | Updated on | WordPress


in your code above use get_the_excerpt() instead of the_excerpt(), because the last one will output the excerpt to the screen, and not pass it to your other functions.

Using a menu walker add a custom item at the end of the menu’s items

Posted by Prem Tiwari | Updated on | WordPress


Using a menu walker add a custom item at the end of the menu’s items. You don’t need a walker in this case. A filter called wp_nav_menu_items is available. It allows you to edit the …

Is it bad practice to create own table for a plugin?

Posted by Prem Tiwari | Updated on | WordPress


I rarely disagree with otherwise knowledgeable users, but in this case I can’t help it. In my opinion calling the usage of non-core database tables bad practice per se is just simply wrong. The choice …

Use WP init hook to call other hooks?

Posted by Prem Tiwari | Updated on | WordPress


Use WP init hook to call other hooks? In general: Yes, wait for a dedicated hook to start your own code. Never just throw an object instance into the global namespace. But init is rarely …