Warning: Cannot modify header information – headers already sent by

Most of the time we donot actually care about leaving the blanks spaces before and after the “php” tag which results on “Warning: Cannot modify header information – headers already sent by (output started at /path/blog/somefile.php:4)“” .

The above problem could be solved by removing the blank spaces before “<?php” tag and after “?>” tag. and make sure the last characters are ?>, placed at the last line with no space in between.

Changing WordPress’ Autosave Frequency and Post Revisions

WordPress has a very nifty autosave feature which can be a lifesaver to anyone who uses WordPress. The downside to WordPress’ autosave, is that it creates a bunch of draft posts increasing your mySQL database size, especially if you write the post within WordPress’ post editor.

If desired, it is possible to change WordPress’ autosave frequency, or even disable the WordPress autosave feature entirely. Furthermore, if you wish to disable WordPress’ post revisions, or limit the total number of post revisions, both are simple to do in WordPress.

The following code snippets will need to be placed in your WordPress install’s wp-config.php. It’s a simple copy and paste, but be careful. If you mess up your WordPress install’s wp-config.php, the WordPress site will break. If you break your WordPress site while editing the wp-config.php file, undo your changes and re-save your WordPress install’s wp-config.php file and everything should be fixed.

How to Change WordPress’ Autosave Frequency

Simply paste the following snippet in your WordPress install’s wp-config.php to change WordPress’ autosave frequency to save every 5 minutes. The integer is the total number of seconds between each autosave.

define('AUTOSAVE_INTERVAL', 300 );  // integer is in seconds

How to Disable WordPress’ Post Revisions

Simply paste the following snippet in your WordPress install’s wp-config.php to disable WordPress’ post revisions feature.

define('WP_POST_REVISIONS', false ); // disable post revisions

How to Limit WordPress’ Post Revisions

Simply paste the following snippet in your WordPress install’s wp-config.php to adjust the limit of WordPress’ revisions that are kept from WordPress’ autosave feature

define('WP_POST_REVISIONS', 3); // alter number of post revisions kept.

Conclusion

It’s that simple to change WordPress’ autosave frequency or even completely disable WordPress’ post revisions. Doing so will decrease the size of WordPress’ database, but will limit the ability to recover from mistakes. So this WordPress modification could come in handy, or cause problems. Be careful.

Source : http://wplifeguard.com/changing-wordpress-autosave-frequency-and-post-revisions/

WordPress:Display a loading image until the page completes loading

To get the ajax loader image until the page loads ,
First add the following code somewhere in header.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" />
<div id="loading-image">
	<img src="<?php bloginfo('template_url'); ?>/images/ajax-loader.gif" alt="Loading..." />
</div>

Then , add the css for the styling purpose

#loading-image {
	background-color: #333;
	width: 55px;
	height: 55px;
	position: fixed;
	top: 20px;
	right: 20px;
	z-index: 1;
	-moz-border-radius: 10px;
	-webkit-border-radius: 10px;
	border-radius: 10px; /* future proofing */
	-khtml-border-radius: 10px;
}

Now finally add the jquery part in the footer,

<script>
jQuery(window).load(function() {
	jQuery('#loading-image').hide();
});
</script>
});

This can be used for magento site too , just need to change the portion that we include in header
Just add the line below in header.phtml

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<div id="loading-image">
	<img src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif', array('_secure'=>true)) ?>" alt="Loading..." />
</div>
Source : http://dancameron.org/code/display-a-loading-image-until-the-page-completes-loading/

WordPress : Fixing Pagination on Custom Queries With query_posts

First off, custom queries are good for calling or excluding certain posts to a page.  Lets say we want to display 5 posts per page from category 10.  The best place to learn how to do this is the Codex.  You would probably start after reading that article like this:

<?php query_posts('posts_per_page=5&cat=10'); ?>

Now technically this would be proper, and it would get you the results you are after, but there would be no pagination.  So if you had many posts and were trying to go to the next page, the same posts would still show.  Here’s how to fix that.  First off, I like to put all my args for query_posts into an array, it’s so much simpler to look at and organize.  So the above as an array would be:

<?php query_posts( array (
     'posts_per_page' => 5,
     'cat' => '10',
));
?>

And that would work the same.  But it’s more organized to me, and so much easier to add more items.  Now  the answer to our problem.  We will take that above query array and get pagination working.

<?php query_posts( array(
     'posts_per_page' => 5,
     'cat' => '10',
     'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),
));
?>

And there we have it!  I think that’s pretty simple.  Always include pagination within your custom query and you’ll be good to go!

UPDATE: Thanks to a reader, and a little scan through the codex, it looks like we may need to update the code above.

<?php query_posts( array(
     'posts_per_page' => 5,
     'cat' => '10',
     'paged' => ( get_query_var('page') ? get_query_var('page') : 1 ),
));
?>
Source : http://www.rvoodoo.com/projects/wordpress/wordpress-tip-fixing-pagination-on-custom-queries-with-query_posts/

WordPress : Front end form submit with jquery form plugin

I have used used the jquery form and tried submitting the form in wordpress but it results in error , form post value is not shown . After long reseach i got the solution about it , form data submission is cannot be done as we normally do in php. For wordpress we need to define the function in function.php of our theme and perform the desire action. I we can to use form as

<form id="myForm"action="http://mysite.com/submitest"method="post"> 
Name: <inputtype="text"name="name"/> 
Comment: <textareaname="comment"></textarea>
<inputtype="submit"value="Submit Comment" name="form_sub"/>

Then add the following code to your
functions.php

<?php
add_action('init', 'form_submit');

function form_submit(){
    if(isset($_POST['form_sub']))
    {
        //here you'll have your form data in a $_POST array, you can check it using a print_r. parse the form and insert the post
        $title = $_POST['name'];
        $content = $_POST['comment'];

        //change the category and author as you want
        $post_obj = array(
                        'post_title' => $title,
                        'post_content' => $content,
                        'post_category' => array(1), //Uncategorized
                        'post_status' => 'draft',
                        'post_author' => 1 //Admin
                       );
        $id = wp_insert_post($post_obj);

        //check if successfully submitted
        if(isset($id) && !is_wp_error($id))
        {
            //redirect to a thank you page, make sure the slug is 'thank-you'
            wp_redirect(home_url('/thank-you'));
            exit;
        } 
    }
}
?>
Source : http://wordpress.stackexchange.com/questions/33896/front-end-submit-form-with-jquery-form-plugin

WordPress path url in js script file

To get the site url in the js file we can have different ways but worked for is listed below.
You could avoid hardcoding the full path by setting a JS variable in the header of your template, before wp_head() is called, holding the template URL. Like:

<script type="text/javascript">
var templateUrl = '<?= get_bloginfo("template_url"); ?>';
</script>

and call in js file

$("#nav-shadow li").append('<img class="shadow" src="'+templateUrl+'/images/shadow.jpg"/>');
Source : http://stackoverflow.com/questions/5221630/wordpress-path-url-in-js-script-file
Posted By AJJ

Add Custom JavaScript and Stylesheet in wordpress

We can directly put it in the header section as we normal does but sometime it maynot work in case of admin.
We can include following code in function.php

function mytheme_custom_scripts() {

	if ( ! is_admin() ) {
		$scriptsrc = get_stylesheet_directory_uri() . '/js/';
		wp_register_script( 'myhandle', $scriptsrc . 'myscript.js', 'jquery', false );
		wp_enqueue_script( 'myhandle' );
	}

}
add_action( 'wp_enqueue_scripts', 'mytheme_custom_scripts' );

and for case of css add the following code

 wp_enqueue_style('thickbox', get_bloginfo('siteurl') . 'wp-includes/js/thickbox/thickbox.css', false, false, 'screen');
        wp_enqueue_script('mthickbox');
Source:http://wordpress.org/support/topic/how-can-i-add-custom-javascript-and-stylesheet-in-headerphp-file-1

Custom image size and autocrop options

WordPress provides different sizes of images , the size of the uploaded image can be edited form Setting > Media and give the required value .But sometime we may need other sizes imaged too so for that purpose we can use the function.php of the theme for custom options. I found it from

http://buckleupstudios.com/blog/auto-resize-wordpress-featured-image-and-crop-if-necessary/

Just add

add_image_size($name, $width, $height, $cropBoolean);

For example : add_image_size('featuredImageCropped', 250, 200, true);

 

Limit excerpt length by characters (Multiple excerpt)

I wanted to have multiple excerpt for my site in wordpress . I googled and find numerious one but

http://wordpress.org/support/topic/limit-excerpt-length-by-characters helped me alot.
We can simple add

 function get_excerpt($count){
 $permalink = get_permalink($post-&gt;ID);
 $excerpt = get_the_content();
 $excerpt = strip_tags($excerpt);
 $excerpt = substr($excerpt, 0, $count);
 $excerpt = substr($excerpt, 0, strripos($excerpt, &quot; &quot;));
 $excerpt = $excerpt.'... &lt;a href=&quot;'.$permalink.'&quot;&gt;more&lt;/a&gt;';
 return $excerpt;
 }

and it by

echo get_excerpt(125);