wordpress auto refresh content - Blogging for Beginners learn Seo online free step by step

wordpress auto refresh content

Depending on the requirements, WORDPRESS auto-refresh functionality can be used in many ways. It can be used in landing pages to redirect to a specific page or posts after a certain time interval. With some tweaks in the website header, WordPress posts and pages can be automatically refreshed.

It can be used in websites which provide live scores of sports like a cricket score.

Auto page refresh in WordPress can be used in the following ways

Insert some PHP codes into the theme file header.php. You need basic knowledge of PHP or WordPress editing at least.

General code

0
1
2 <META HTTP–EQUIV=“Refresh” CONTENT=“5; URL=”> 


where:

CONTENT is a time in seconds after which page will be refreshed or redirected.

URL is the URL where you want to redirect after the time specified in CONTENT.

Note: before editing the header.php file of your WordPress theme
it is advisable that you should backup it before editing.

Page Auto Refresh:

a. If want to refresh the home page of WordPress site after 5 seconds
enter following code between <header> </header> of header.php

0
1
2<?php 
3
4 if(is_home()) 
5
6{ 
7 echo ‘<META HTTP-EQUIV=”REFRESH” CONTENT=”5″>’ ; 
?> 

Note: this code will not work if you have set a page as a home page by

Settings=>Reading=>Front page displays=>A static page (select below) for this you have to enter following code between <header> </header> of header.php

0
1
2 <?PHP 
3
4 if(is_front_page() ) 
5
6 { 
7 echo ‘<META HTTP-EQUIV=”REFRESH” CONTENT=”5″>’ ; 
?> 

b. if want to refresh a particular post of post id 17 after 10 seconds .
enter following code between <header> </header> of header.php

0
1
2 <?PHP 
3
4 if(is_single( ’17’ )) 
5
6 { 
7 echo ‘<META HTTP-EQUIV=”REFRESH” CONTENT=”10″>’ ; 
?> 

c. I want to refresh the posts in bulk you have to apply a condition on an array of posts as shown in below code.
enter following code between <header> </header> of header.php

0
1
2 <?php 
3
4 if(is_single( array( 17, 19, 1, 11 ))) 
5
6 { 
7 echo ‘<META HTTP-EQUIV=”REFRESH” CONTENT=”10″>’ ; 
?> 

Where 17,19,1,11 are posted id of posts you want to refresh after 10 seconds.

d. If want to refresh a particular page after an interval of 23 seconds with page id of 47.
enter following code between <header> </header> of header.php

0
1
2 <?php 
3
4 if(is_page( 47 )) 
5
6 { 
7 echo ‘<META HTTP-EQUIV=”REFRESH” CONTENT=”23″>’ ; 
?> 

e. If want to refresh the pages in bulk you have to apply a condition on an array of the page as shown in below code.

enter following code between <header> </header> of header.php

0
1
2 <?php 
3
4 if(is_page( array( 42, 54, 6 ) )) 
5
6 { 
7 echo ‘<META HTTP-EQUIV=”REFRESH” CONTENT=”21″>’ ; 
?> 

Where 42,54,6 are page id of pages you want to refresh after 21 seconds.

f. If want to refresh a particular Category archive page after an interval of 5 seconds with category id of 7.

enter following code between <header> </header> of header.php

0
1
2 <?php 
3
4 if(is_category( ‘7’ )) 
5
6 { 
7 echo ‘<META HTTP-EQUIV=”REFRESH” CONTENT=”5″>’ ; 
?>


This code can also be extended for a number other pages like author page, archive pages etc.

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.