WP-Mix

A fresh mix of code snippets and tutorials

Category Archive: WordPress

Posts about WordPress

Page 3 of 17

Restore Removed Query String Paramaters in the WP Admin Area

Developing my WordPress plugins recently, I noticed that Chrome was removing the query-string parameters from the URL as displayed in the browser’s address bar. Likewise Firefox and others were not showing the full URL in the address bar, which was making development difficult, as I was testing URL redirects involving query parameters at the time.

Add Defer and Async to WordPress Enqueued Scripts

When adding JavaScript in WordPress, it sometimes is necessary to add attributes such as async and defer to the <script></script> tag. Here is a technique to do it with any WordPress version 4.1 and better.

Disable Chrome XSS Auditor

Working on WordPress development and testing HTML forms in Chrome browser, I ran into the following error: This page isn't working Chrome detected unusual code on this page and blocked it to protect your personal information (for example, passwords, phone numbers, and credit cards). ERR_BLOCKED_BY_XSS_AUDITOR

WordPress Disable Self Pings

Depending on your WordPress configuration, plugins, and so forth, your site may be suffering from “self-pings”. Self-pings are pingbacks from your own domain, which are not necessary and look kind of silly displayed alongside other, actual pingbacks. If your site is haunted by self-pings, here is a quick code snippet to stop them.

WordPress template_redirect Example

Quick code snippet showing basic use of the WordPress template_redirect action hook. This is provided as a quick copy/paste reference for WordPress developers. This hook is useful for customizing any functionality requiring full query information.

Display WordPress Theme Screenshot

Most good themes include a screenshot, primarily to be displayed on the Themes screen in the WP Admin Area. Of course, theme screenshots can be displayed anywhere, even on the frontend.

WordPress: Display Site Creation Date

I’m surprised that WordPress doesn’t provide a function for getting the site creation date. Knowing when the site was set up can be useful for all sorts of things. Copyright dates. Bragging rights. Whatever. If you want to display the date your site was first installed, here is one way to do it.

WordPress Remove Screen Options

Normally the “Screen Options” tab is an awesome little WordPress feature. Located on various screens in the WP Admin Area, the Screen Options tab toggles open any available settings. Like which meta boxes to display, layout columns, editor auto-height, and other options depending on which screen you are viewing. But there may be cases where […]

WordPress: Get All User Roles

WordPress makes it easy to get the current user’s role(s) by using wp_get_current_user(). But what if you want to get all roles from all users. Like a list of every role that is used on your site. Well good news, WordPress provides a global object named $wp_roles that provides the information. So if you’re looking […]

Rename uploaded files in WordPress

Here is a function used in my free WordPress plugin User Submitted Posts that enables you to rename WordPress media uploads. So for example, if the user uploads a JPG image named “sweet-ride.jpg”, the following function will append a random string to rename the file “sweet-ride-random.jpg”, where “random” is a random alphanumeric string containing 20 […]

WordPress Get Edited Post ID

Working on my plugin Disable Gutenberg, I needed a way to get the ID of an edited post. Not on the front-end, but on the “Edit Post” screen in the WP Admin Area. Unfortunately WordPress does not provide a built-in core function for handling this, so it’s necessary to roll our own solution.

Get Current Post Type in the WordPress Admin Area

In WordPress, you can create posts, pages, or any custom post type. Within your theme template, you can get the current post type using the core WP function, get_post_type(). But that doesn’t work in the Admin Area. For example, my Disable Gutenberg plugin provides conditional functionality to the “Add New” and “Edit” screens based on […]