I want to make page cache of static pages in my WordPress theme (and basically I know how to implement it)
The problem is that when making theme - the first time when I "get any control" about what is happening is inside functions.php file of theme, and this file is loaded about 1 sec after request starts (before it is loading all wordpress functions stuff, I quess some sql - but I dont need that all as I'm using page cache, just want to render saved html - btw. thats what is cache about for me).
So the question is - Am I able to - from level of theme - take control of WordPress initialization before theme functions.php? - the best would be as soon as possible after request start
Why? Getting html from cache takes 0,05s in my case, and time from request start to functions.php is 1s so in sume it gives 1,05s that I could reduce to like 0,1s if I'm able to 'capture' request earlier.
I dont want to modify non-theme files like WordPress core files as many people will use this theme, but if there is no other way than maybe but I dont feel it would be good practice?
i guess this might help: http://codex.wordpress.org/Plugin_API/Action_Reference/init
this hook gets executed when wordpress has loaded but before anything is saved
Create a drop-in plugin called advanced-cache.php, put it in wp-content (not wp-content/plugins), put define('WP_CACHE', true); in wp-config.php, and get to work.
Make sure not to cache:
admin pages
404 pages
POSTed pages
pages with query strings
pages that will be redirected
etc
Related
I made a simple WordPress plugin, it works perfectly fine on my own server, but not on the live website of a friend.
It is a very basic Referral plugin, I used cookie to save the referrer ID, then used user_register hook to save it in database after some one signs up.
This is the part that saves the Referrer ID:
function set_referrer_cookie() {
setcookie("referrer_id", $_GET['ref'], time()+3600, "/");
}
add_action('init', 'set_referrer_cookie');
The cookie is not set many times, at first I was puzzled, but after a lot of testing, I believe this is caused because of caching (he has a lot of plugins, such as Breeze caching etc)
How can I make sure, the cookie is set all the time?
Is there any way around this?
Edit:
After running each URL in the browser, the plugin saves a new .php file in its /breeze/cache/ folder,
I think it is the Output of the PHP file, as the echo value is shown in plain text in it, and it's all HTML,
so it appears the Breeze plugin caches the output of PHP in a file, and serves it again as a static HTML, with no option to exclude set_cookie in the admin panel... is there any way to work around this?
I am creating web portal in WordPress for that I am using i-craft WordPress theme. But my website page loading very slow at initial load that is before loading of all content. Its taking 8 - 10 sec to initial load. I know this is happening due to lots php code with lots of functions and loops. I want to remove all unnecessary code or php file. As my website belongs to only single theme and I don't want to add post functionality etc. so which file/php code/information in database I have to remove that will helps website to load initially faster. Or is there any way to make loading very fast without removing code or files.
You can use
https://gtmetrix.com
on here you can check your site analytic report .and you want to do minify your css and js file.and also images .
I have a file structure like
example.com/mywordpress/ --contains WordPress
example.com/custompreview.php --preview getter outside wordpress
I am using wp-load.php to load wordpres and using its contents. I am able to recive published posts with no problem, I even know how to make query for previews but when preview get parameters comes to the script outside the wordpress folder (custompreview.php) obviously the wp-load.php calls exit and shows only access error message.
Example is worth thousand words:
example.com/custompreview.php?preview=true&preview_id=64&preview_nonce=1f2477c5d2&post_format=standard
Shows only message "You do not have permission to preview drafts"
What is causing this? What is the wp-load.php checking for? How to fix this? :)
If you are getting this while logged in -
the session cookie may be limited to the /mywordpress folder.
Unless explicitly specified, the cookie will be valid in the subdirectory it was set in (and all children).
I'm not sure whether it is possible to change WP's session cookie behaviour, but it may help to put the PHP file inside /mywordpress.
The Problem
My website has some JavaScript and PHP that I include on each page to allow login and cookie processing for persistent login, using a header that changes if the user is logged in, and these work successfully. I would like to add a pages that contain WordPress blogs/forums, while keeping my header and all its processing at the top. Is there any way to do this? My understanding is that WordPress controls the entire page with its own <head> and <body> tags and info. The backup plan is to have the blog/forum pages be somewhat rogue pages with a separate header that links back to the main site.
What I've Tried
Figure out where WordPress sends the HTML and modify that page: They use a network of include() statements to decide what to show, and I'd be concerned that a change in the WordPress admin panel would overwrite changes I make, or that the WordPress control panel code makes changes by adding code before/after a certain line, and I'd somehow break that.
Put the blog pages in an iframe: Prevents blog permalinks and seems to undercut the SEO benefit of a blog. Even if I could get around this with some kind of .htaccess hackery, I'm concerned having the page in an iframe could cause browsers to block some WordPress functions for security reasons.
Code I Want To Include
session_start(), cookie handling and database connect in PHP at the top
A header just after <body> that I include using <?php include('header.php')?>
headerProcessing.js script that I include in the head tag (along with jquery)
CSS file for header styling
I'm stumped and can't seem to find anything with Google - any help appreciated. Thanks!
You'd be better off to join WordPress as opposed to fighting it.
WordPress provides dozens of ways to access and manipulate page content. The easiest of which is to add hooks to wp_head and wp_footer in your theme's function.php.
I'd also encourage you to read about WordPress Theme Development.
I'm quite new to Drupal and want do some editing of the header. I want a custom toolbar to appear on every page. I've already created that toolbar in a file called toolbar.php. It has a layer which is fixed and will appear on top of every page.
How do I include the toolbar.php in the header template of drupal?
The toolbar refers to $user which is a global Drupal variable and I want to test toolbar.php before publishing it to the site. Is there anyway I can do that?
Regards,
Dasith
Of the two methods above the first is easier if you understand the basic idea of html and CMS templates, the second will be easier if you are a programmer.
First thing to check is that you really need to do this! Can't you restyle one of the existing menus (Primary or secondary) to do this - will make your life (and anyone who works on the site in the future) a lot easier.
The other thing you can do is look into adding an output region, basically something where you put the php into a drupal friendly format and then effectively do a 'drupal print'. This is how the toolbar, search box etc are done. You still need to alter the templates as above.
Yes for sure. If you want to have the html produced by your function/file appear on every page of the site then you will need to over-ride the page.tpl.php file in the theme you are using and essentually add the html to that file.
To gain access to the $user variable, just declare it in your script.
global $user;
open page.tpl.php file in a code editor and save as page-front.tpl.php (with two dashes if you are using Drupal 7.. one dash with Drupal 6) and upload it to your theme's directory. Clear your cache by going to configuration->Performance->Clear All Cache. Then referesh the page. Now your homepage is using page-front.tpl.php as it's template file. Every page will need its own template file. The page machine name comes after the hyphen so the user page template uses page-user.tpl.php. You can edit it as you want. The proper way to really do this is to use hook_theme() to pass variables to the template file. One variable could be the html which creates your custom header.
See also http://drupal.org/node/457740 Beginners Guide to over riding theme output