1
How to remove deprecated errors while running new php versions
2
Find the latest post for each author and then group the results
3
Get the current page name in WordPress using $pagename
4
How to Create a folder in wordpress if it doesn’t already exist
5
How to Redirect WordPress Admin Pages to Any Location You Want
6
How to Hide/Remove the Buttons From Attachment Media Window in WordPress
7
How to Display WordPress $hook_suffix as Admin Notice
8
Hide/Exclude a Page in Edit Pages Section in WordPress Dashboard
9
How to Add Google Trends Graph in Post/Page via Shortcode
10
How to Add body_class to Specific WordPress Page Templates

How to remove deprecated errors while running new php versions

If you’re running PHP code on the server having latest version of PHP, and you’re using deprecated code of PHP. Then, you might get the error something like below: Deprecated: Assigning the return value of new by reference is deprecated Note: Errors code be different, but for deprecated error, the error will have Deprecated written.[…]

Read More

Find the latest post for each author and then group the results

Following is a WordPress database query to fetch the latest post for each author and then group the result. By using this query, you’ll be able to only get a single latest post from each author. Here is the code for displaying only one latest post from each author: SELECT wp_posts.* FROM wp_posts WHERE wp_posts.post_status='publish'[…]

Read More

Get the current page name in WordPress using $pagename

Following is a code snippet to get the current page name in WordPress using $pagename. The global variable $pagename is in the wp-includes/theme.php, and you can find inside get_page_template() function. $pagename variable is called before your page theme files are execute. When you should use $pagename WordPress global variable? 1. The variable is only set[…]

Read More

How to Create a folder in wordpress if it doesn’t already exist

Sometimes working with WordPress, you find out that your (wp-content/uploads) folder or any folder is missing. So, you might feel that you should create a code in theme that checks for the folder and if not found creates it. Following is a sample code for creating a folder in wordpress if it doesn’t already exist.[…]

Read More

How to Redirect WordPress Admin Pages to Any Location You Want

If you are facing a situation to redirect WordPress admin pages to some location. The following code will allow you redirect any admin page you want to any location according to the user “capability or role“. Paste the code inside functions.php. function wpulti_admin_pages_redirect() { global $pagenow; $admin_pages = array( 'edit-tags.php?taxonomy=category', 'edit-tags.php?taxonomy=post_tag', 'link-manager.php', 'options-writing.php', 'options-reading.php', 'options-discussion.php',[…]

Read More

How to Display WordPress $hook_suffix as Admin Notice

Hook Suffix is page in WordPress and that is generated everytime you add  a new admin menu, for example, add_submenu_page(), add_menu_page(), add_options_page(). These kind of functions returns a special value called Page Hook Suffix. If you are looking for a way to use the hook_suffix later, register a hook on a particular page load-hook_suffix. Following[…]

Read More

How to Add Google Trends Graph in Post/Page via Shortcode

wordpress logo

Google Trends is a service provided by Google Inc. This service shows the most searched term, based on Google Search. Google also provides an API to display Google trends in any website. But we’ll implement Google Trends in WordPress by creating a shortcut for Google Trends. Paste the following code in functions.php. The code will[…]

Read More

How to Add body_class to Specific WordPress Page Templates

wordpress logo

body_class is a template tag in WordPress helping us to style our themes more effectively with CSS. This function automatically add different classes to your element. We usually use it inside header.php like: <body <?php body_class($class); ?> > If you’ll add above code to header.php, it will apply to all WordPress pages. But what you[…]

Read More