Removing and tags in WordPress posts

This happens because of WordPress’s wpautop. Simply add below line of code in your theme’s functions.php file remove_filter( ‘the_content’, ‘wpautop’ ); remove_filter( ‘the_excerpt’, ‘wpautop’ ); For more information: http://codex.wordpress.org/Function_Reference/wpautop

Retrieve WordPress root directory path?

Looking at the bottom of your wp-config.php file in the wordpress root directory will let you find something like this: if ( !defined(‘ABSPATH’) ) define(‘ABSPATH’, dirname(__FILE__) . “https://stackoverflow.com/”); For an example file have a look here: http://core.trac.wordpress.org/browser/trunk/wp-config-sample.php You can make use of this constant called ABSPATH in other places of your wordpress scripts and in … Read more

WordPress filter to modify final html output

WordPress doesn’t have a “final output” filter, but you can hack together one. The below example resides within a “Must Use” plugin I’ve created for a project. Note: I haven’t tested with any plugins that might make use of the “shutdown” action. The plugin works by iterating through all the open buffer levels, closing them … Read more

WordPress Site Keeps Getting Hacked

First of all – DON´T PANIC. Installing antivirus or security plugins at this point will rarely help – the malisious code has already server access. 1 – Change ALL the passwords for FTP, mysql , DB , Cpanel , WHM , SSH ( disable if not need ) etc. anything with access. 3 – Check … Read more

Remove category & tag base from WordPress url – without a plugin

If you want to remove /category/ from the url, follow these two steps: Go to Settings >> Permalinks and select Custom and enter: /%category%/%postname%/ Next set your Category Base to . Save it and you’ll see your URL changed to this format: http://yourblog.com/quotes/ (Source: http://premium.wpmudev.org/blog/daily-tip-quick-trick-to-remove-category-from-wordpress-url/)

Using WPDB in standalone script?

The best(fastest and safest) way to load only load the core functionality of WordPress is to use the SHORTINIT flag like this: define( ‘SHORTINIT’, true ); require( ‘/path/to/wp-load.php’ ); //Here you can use WordPress core features, for example the $WPDB object For more information about this and see what is loaded, is to check the … Read more

Listing , pagination and search custom user data by role in wordpress

<?php if (!defined(‘ABSPATH’)) { exit; // Exit if accessed directly } $search_term = sanitize_text_field($_GET[‘s’]); $only_fields = array( ‘user_login’, ‘user_nicename’, ‘user_email’,’ID’ ); $count_args = array( ‘role’ => ‘enter-custom-user-role’, ‘fields’ => $only_fields, ‘search’ => ‘*’.esc_attr( $search_term ).’*’, ‘number’ => 999999 ); $user_count_query = new WP_User_Query($count_args); $user_count = $user_count_query->get_results(); // count the number of users found in the … Read more