Dynamic Content not working with WP Super Cache - wordpress

wonder if someone can help. I am trying to add a cart widget to the header of a woocommerce enabled site. However, when WP Super Cache is enabled, the widget doesn't update when something is added to the cart, understandably.
I am trying to add the following so the widget isn't cached:
<!--dynamic-cached-content-->
<?php echo time(); ?>
<!-- my_dynamic_content(); -->
<!--/dynamic-cached-content-->
I have just displayed the time in this case to see if I can get it working.
I have set the caching to PHP cache, with late init and dynamic caching enabled but the time still doesn't update when I'm logged out of the administrator.
I have trailed through documentation to see if there is another way to get this working but so far I have not found a way.
Can anyone point me in the right direction? Maybe I've got this completely wrong!
I just want one widget to be dynamic in the header.
Thank you in advance.

There are multiple types of cache for web applications, and WordPress has ways to take advantage of all of them.
Plugins like WP Super Cache, W3 Total Cache, and Batcache as well as server components like Varnish and Nginx implement page caching. These tools store a copy of the complete page and use that cached copy every time the same URL is requested. This is the fastest cache available, but the down side is they return the same HTML to everyone.
If you want to use a page cache but still have dynamic elements like your header widget, you'll have to render them in JavaScript.
If you've written your own theme, you can implement fragment caching by storing the rendered HTML of different sections of the page except the part you want to be dynamic. There's no plugin you can download that'll do it for you. You'll need to make your own judgement calls about what needs to be cached and for how long.
Lastly, you can just cache the data used to render pages. Look for information on WordPress persistent object caching or write code to use WordPress's Transients API. A persistent object cache plugin can automatically store the results of WordPress's queries to something like Memcached or Redis if you have that available.

Related

Logged-in Users need to Refresh page to see content

Hi I'm having an issue with a site where visitors need to be members to access certain pages, but once logged in they go to these pages and still see the 'not logged in' page and need to refresh to view the actual content.
This obviously leads to a lot of bounces and I'd like to fix so that they see the content right away.
The root issue comes from some cache settings or something from the host - unfortunately we can't change host (and it's not a regular hosting company with a website but a design company reseller) for the time being. This issue does not occur in our offline environment of the same site.
I've already had to add a ?randomnumber to the stylesheet so it loads new versions properly. I was wondering if something like this would work - but dynamically as pages are being added all the time by different admins.
Or any other solutions also appreciated!
Thanks
Like you said, tweaking the caching settings would be the most ideal. But since that's not an option, I'd suggest adding a random, meaningless query string to the URL of the member pages so that it's seen as a 'new page' and (likely) won't cache.
So instead of /member-page
Direct them to /member-page?cache-buster=randomlyGeneratedStringHere

Caching plugins will affect the wordpress shop stock control?

To avoid a lot of memory consuption on my server. I am thinking to activate server caching and using wordpress caching plugins as well.
However, my wordpress is an online store. So, I am unsure that how it'd work out. Like will enabling caching will cause delays in the stock control in woocommerce?
Like I am afraid if a customer buys an item, it wont be reduced by 1 immediately because of the caching plugin?
Let me know if that is the case?
Regards
You can use a cache plugin with a Wordpress powered online stores, but you must exclude all store related pages from being cached so that they remain dynamic. If they are not, you store will not work correctly. This page will help you correctly configure your WooCommerce store in conjunction with various mainstream caching plugins.

How to make changes are not visible in userside using wordpress

I want to edit contents of the existing page in wordpress.It is a live site so user side should not be changed
untill i want to publish that after all changes made to that page.Is there any plugin or what
i have to do for this.
Anyone please help me.
It depends what sort of changes. As noted above if you're channing post contents if will be enough not to publish them, but I guess you already now that.
However if you want to change appearance of the site then caching plugin might help. E.g. with w3 total cache you can do any change to template/css/php and so on and only logged in users will see changes (any non logged in user will get cached version of the page until you clean cache or cache expires).
If you have also users which are logging in into your wordpress, then I'm not aware of already made plugin that have such functionality - you probably would have to create development version of your site and test changes there.
For content - agree with previous answers.
But if you are changing the theme and want some changes to be visible only for you (admin) then you can use is_admin() function to print out different content for admin (new one) and different for other users (old one).
http://codex.wordpress.org/Function_Reference/is_admin

Using iframes to add dynamic content to statically cached pages

I have a wordpress based site which makes use of a full page caching system. Problem is that I need to add dynamic content for logged in users. Right now I'm keeping the caching enabled for non-logged users and disabled for the logged ones via cookie check.
Would inserting the dynamic content in an iframe be an acceptable solution to extend the full page caching to all the users? Or any better ways?
Another approach would be to pull in the dynamic contents via AJAX. Of course your page will not be accessible without Javascript, but that may or may not be an issue.

Virtual pages for my plugin

I am currently in the process of making a WordPress Plugin which is going to parse some external data (products) from various web services and present them as normal pages in WordPress.
I would like to avoid actually creating the pages programatically and instead just generate them on the fly to avoid any synchronization issues if a product is deleted and so forth.
My plugin is going to have a base url in which it will hook on to, for example /products/,
and then I would generate each product page by calling /products/some-product-name/.
I also anticipate the need for uri's like /products/category/some-category-name/ which I will use to list all items in that category.
Since I am new to WordPress plugin development, I am looking for some tips and advice to get me started on the right foot. Any help is highly appreciated ;)
I suppose it really depends on where/how you're getting your info from these web services, but I can imagine that the easiest way would be to setup a page as a controller and have it parse out some RSS or XML to build these "virtual pages" by request, so that you're not storing anything in the DB and if the info requested doesn't exist than yes 404 it.
I solved this by adding a filter to rewrite_rules_array and an action catching template_redirect.

Resources