WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I read about 2 methods for initializing wordpress function outside of wordpress files so We can use these functions on any page or website outside the wordpress blog.

Which one of these 2 methods is the correct one? And what is the uses for each method if both are correct? What is the deference between using this method or the other?

Method 1 :

<?php 
define('WP_USE_THEMES', false);
require('./wp-blog-header.php');
?>

Method 2 :

<?php 
define('WP_USE_THEMES', false);
require('./wp-load.php');
?>
share|improve this question
    
Which WP functions are you trying to use "outside of WP" and why? Either of these methods will still load the WP environment (albeit without theme support), so you're still invoking functions inside of WP. – EAMann Mar 27 '12 at 21:41
    
I am trying to understand the difference between the 2 methods. What I will do is integrate the wordpress theme with my support script. so will need the header, footer and the loop from wordpress plus some support for widgets and other plugins – alhoseany Mar 27 '12 at 22:33
    
I really doubt this is the way you want to do things ... there are better solutions than trying to bootstrap WordPress itself. – EAMann Mar 27 '12 at 22:57
    
I am wide open for suggestions, I am looking for the best way to do things? what is the best way to integrate wordpress theme with outside web application? – alhoseany Mar 28 '12 at 10:29
up vote 17 down vote accepted

There's little difference between the files. When you view a WordPress page, the first file called is index.php. And it is, essentially, your "Method 1:"

define('WP_USE_THEMES', true);

/** Loads the WordPress Environment and Template */
require ('./wp-blog-header.php');

The blog header file (that queues up the rest of WordPress) loads wp-load.php directly and fires up WordPress itself. Here's most of wp-blog-header.php:

if ( !isset($wp_did_header) ) {

    $wp_did_header = true;

    require_once( dirname(__FILE__) . '/wp-load.php' );

    wp();

    require_once( ABSPATH . WPINC . '/template-loader.php' );

}

So the difference between your two methods is ... what's loaded.

Method 1 is exactly what WordPress does to load itself (with the exception of turning themes off). So if you need all of WordPress and want to fire all of the default hooks/actions, go with that route.

Method 2 is just a further step down the line. It loads all of WordPress, but doesn't call wp() or invoke the template loader (used by themes). Method 2 will be a little lighter-weight, but should give you the same functionality.

share|improve this answer
2  
Is there a diagram or something that maps all these files out? I saw one long ago but I can't find it. – ninja08 Jun 12 '15 at 16:53

Method 2, wp-load.php is the access to all functions of WP, that's all. The first line you can remove, not necessarily.

share|improve this answer
1  
what does that first line even means ? – Sagive SEO Mar 27 '12 at 22:35
5  
The first line tells WordPress not to load all of its theme support functionality. Basically, load fewer files. – EAMann Mar 27 '12 at 22:52
    
Is the first line needed only for the first method? – Matteo Oct 5 '14 at 13:46

Sometimes loading the functions.php of the theme can cause you some trouble. It was breaking the html of my other page. So that's what I did and solved my problem:

define('STYLESHEETPATH', '');
define('TEMPLATEPATH', '');
require_once(RAIZ_WORDPRESS."/wp-load.php");
share|improve this answer

@ninja08

We can use xDebug php extension to analyze an script.

just enable ;xdebug.profiler_enable = 1 in your php.ini file by removing ; from first of line and after this restart apache server and run your wordpress site ...now a file created in tmp directory of your xampp server ..open this file with WincachGrind application.

now you can see a map of your script

WincacheGrind Simple Wordpress Analyze

share|improve this answer
    
You should have added this in the comment below ninja08. this is now an incorrect answer. – alhoseany Dec 15 '15 at 7:26
    
@alhoseany yes..i now it... but i dont have enough reputation...and then i decide to do this. – Mostafa Dec 15 '15 at 18:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.