Auto refresh WordPress pages and post

WordPress posts and pages can be automatically refreshed using some tweaks in header of the website.

Auto refresh functionality can be used in many ways depending upon needs.It can be used in landing pages to redirect to a particular page or posts after a certain interval of time.

It can be used in other situations.for example, if the website is moved from root directory to a new directory and want the users to go to new website through root directory then simply create a page in root directory and write the code so that users will automatically redirected to new website directory.

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

Auto page refresh in wordpress can be used in following ways

By inserting some php codes in header.php theme file.
it needs you have basic knowledge of php or at-least WordPress editing.

General code

where:

CONTENT is 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

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

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

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

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

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

e. If want to refresh the pages in bulk you have to apply condition on array of page as shown in below code.
enter following code between <header> </header> of header.php

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 a interval of 5 seconds with category id of 7.
enter following code between <header> </header> of header.php

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

 

 

Related posts

Leave a Comment