How to use WordPress functions/posts outside the WordPress directory

Updated on September 2, 2017

Many of us (webmasters) will try develop an app/extension for chrome or any such to showcase the great contents from the website. So in a way one has to develop from scratch, which is time consuming !. To cut short, you can straight away use your WordPress  functions and posts directly which i will be showing you how to use WordPress functions and posts outside the WordPress directory.

Features :

Coding time reduces
Maintenance will be easy
Duplicity in coding will be reduced
wordpress functions and posts outside wordpress directory
wordpress functions and posts outside wordpress directory

[sc:demobuttons demolink=”http://demo.techglimpse.com/wordpress-functions-posts-outside-wordpress-directory/” boxlink=”http://adf.ly/PkrGB”]

How to include WordPress ?

The key to use WordPress outside the WordPress directory is wp-load.php or wp-blog-header.php file. If you don’t want the WordPress themes, define it to “false”.

define('WP_USE_THEMES', false);
require_once('Absolute Path to wp-load.php');

How to access WordPress functions ?

Once the wp-load.php file is included, the entire WordPress functions is provided to you. Here i will be showing you obtaining recent posts using WordPress functions by running through loop.

$postslist = get_posts($args);
foreach($postslist as $post) {
setup_postdata($post);
 $the_title = get_the_title();
 $the_link = get_permalink();
 $the_content = get_the_excerpt();
 print "<a href="$the_link">$the_title</a>";
 print "<div class='title'>$the_content</div>";
}

Here am getting the title, link and the excerpt content of the post and printing it.

[sc:demobuttons demolink=”http://demo.techglimpse.com/wordpress-functions-posts-outside-wordpress-directory/” boxlink=”http://adf.ly/PkrGB”]

Was this article helpful?

Related Articles

Leave a Comment