How to store widget fields data as an array?

Posted by Prem Tiwari | Updated on | WordPress


Here is a very simple demo widget:

Where is the old post permalink slug stored?

Posted by Prem Tiwari | Updated on | WordPress


We determined that the slug was not stored in postmeta meta_key _wp_old_slug. In a final attempt to find where this slug is stored. I performed a search for the exact phrase of writing and found a few results. The one …

Where to securely store API keys and passwords in WordPress?

Posted by Prem Tiwari | Updated on | WordPress


There is no absolutely safe way to store such information permanently. You have two options to increase security a little bit: Use the options table and encrypt the data Use a strong encryption method, and bind …

Is there a way to set default custom fields when creating a post?

Posted by Prem Tiwari | Updated on | WordPress


Is there a way to set default custom fields when creating a post? This is the proper method to add custom fields support (you don’t get the blank fields when edit posts)

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 …

WooCommerce assign an author to a product

Posted by Prem Tiwari | Updated on | WooCommerce


WooCommerce assign an author to a product. Simply use add_post_type_support:

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:

Deactivate Gutenberg tips forever – not Gutenberg

Posted by Prem Tiwari | Updated on | Gutenberg


Gutenberg tips can be disabled by using dispatch(‘core/nux’).disableTips() (NUX package) and action hook enqueue_block_editor_assets. Use the below example code in your functions.php file: Now use the below example code in your custom JS file:

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: