10 tricks and tips to use with WordPress

WordPress tips and tricks

In this article I tried to bring tips and tricks about WordPress. You will see tips on where to get the information you need and still some interesting tricks to improve your WordPress site.

USE THE WORDPRESS CODEX SCRIPTS

WordPress already comes with a ton of scripts inserted into your Codex. There are several lines of code built in JQuery that you can use with functions such as wp_enqueue_script () and wp_enqueue_style (), which can save your work of customizing your WordPress site, are options that may even prevent you from installing plugins unnecessarily.

You’ll find some very useful tips from the WordPress Codex right here at the WP School or you’re interested in learning more about using the functions on the official WordPress Codex page.

DEFINE JPG IMAGE QUALITY

You can create a function in WordPress to set a quality standard for JPEG images, which by default are leveled to 90%. It is not possible for an average user to notice a difference of 100% up to 80%, so I advise you to use the smallest amount in order to conserve space, bandwidth and not to damage the loading of your pages.

FEEDBURNER REDIRECT

FeedBurner is used in almost every blog as a complementary tool in the loyalty strategy of your site’s content readers. Until recently, I used a plugin to redirect the feed from WordPress sites to FeedBurner, until I found the code below to create a simple function that accomplishes this task with ease:

add_action( ‘template_redirect’ , ‘rss_redirect’);

function rss_redirect() {

if ( is_feed() AND !preg_match( ‘/feedburner|feedvalidator/i’, $_SERVER[‘HTTP_USER_AGENT’] ) ){

header( ‘Location: http://feeds.feedburner.com/feed_seu_site’ );

header( ‘HTTP/1.1 302 Temporary Redirect’ );

}

}

ADD CUSTOMIZED FIELDS IN THE USER PROFILE

WordPress does not yet have the ability to add custom fields to your users’ profiles. This task is easily solved as a series of plugins, but also with a simple function as the code below demonstrates:

<?php

add_action( ‘show_user_profile’, ‘wp_profile_fields’ );

add_action( ‘edit_user_profile’, ‘wp_profile_fields’ );

function wp_profile_fields( $user ) {

?>

<h3>Redes Sociais</h3>

<table>

<tr>

<th><label for=&twitter&>Twitter</label></th>

<td>

<input type=&text& name=&twitter& id=&twitter& value=&<?php echo esc_attr( get_the_author_meta( ‘twitter’, $user->ID ) ); ?>& /><br />

<span>Seu Twitter </span>

</td>

</tr>

<tr>

<th><label for=&twitter&>Facebook</label></th>

<td>

<input type=&text& name=&facebook& id=&facebook& value=&<?php echo esc_attr( get_the_author_meta( ‘facebook’, $user->ID ) ); ?>& /><br />

<span>Seu Facebook </span>

</td>

</tr>

<tr>

<th><label for=&twitter&>Linkedin</label></th>

<td>

<input type=&text& name=&linkedin& id=&linkedin& value=&<?php echo esc_attr( get_the_author_meta( ‘linkedin’, $user->ID ) ); ?>& /><br />

<span>Seu Linkedin </span>

</td>

</tr>

</table>

<?php

}

add_action( ‘personal_options_update’, ‘wp_save_profile_fields’ );

add_action( ‘edit_user_profile_update’, ‘wp_save_profile_fields’ );

function wp_save_profile_fields( $user_id ) {

if ( !current_user_can( ‘edit_user’, $user_id ) )

return false;

update_user_meta( $user_id, ‘twitter’, $_POST[‘twitter’] );

update_user_meta( $user_id, ‘facebook’, $_POST[‘facebook’] );

update_user_meta( $user_id, ‘linkedin’, $_POST[‘linkedin’] );

}

ADD POST TYPES PERSONALIZED ON YOUR FEED RSS

It is not uncommon to see the use of Post Types for content segmentation of WordPress sites, an excellent tactic by the way. But this content is not available to anyone who subscribes to your site Feed, the function below solves this problem:

add_filter(‘request’, ‘wp_custom_feed’);

function wp_custom_feed( $vars ) {

if ( isset( $vars[‘feed’] ) ) {

$vars[‘post_type’] = get_post_types();

}

return $vars;

}

PERSONALIZED QUERIES TO THE DATABASE

If you need more information than WordPress functions offer you, you can use the wpdb class to query the database directly. Here’s how to use the class in the code below:

$recent_users= $wpdb->get_results( &SELECT display_name, user_registered FROM $wpdb->users ORDER BY user_registered DESC LIMIT 0,10&);

Related Posts