I'm trying to set up an independent PHP file which has the ability to use a shortcode of a plugin currently installed. This file is to be completely external from my current Wordpress installation.

I'm doing this as the php file (and ultimately plugin shortcode functionality) needs to be called by ESI as my website is being handled by Varnish.

The plugin I'm using: http://wordpress.org/extend/plugins/custom-content-by-country/

My current and unsuccessful attempt at making this work:

<?php

// This section is experimental and not working (also the 'do_shortcode...' sections below)

include ("../../../wp-load.php");
include ("../../../wp-includes/shortcodes.php");

// end of section

$cwd = getcwd();
$path = substr($cwd, 0, strpos($cwd, 'wp-content/'));
require $path . 'wp-blog-header.php';
global $adrotate_config;

do_shortcode('[CBC country="us" show="y"]'); // not working correctly
echo adrotate_group('1'); // Working Correctly
do_shortcode('[/CBC]'); // not working correctly

do_shortcode('[CBC country="us" show="n"]'); // not working correctly
echo "Hello World!"; // Working Correctly
do_shortcode('[/CBC]'); // not working correctly

?>

Any help would be greatly appreciated. Thanks

有帮助吗?

解决方案

Did you try to include wp-blog-header.php instead?

Your external file:

define( 'WP_USE_THEMES', false );        
require('wp-blog-header.php');       

do_shortcode('[CBC country="us" show="n"]');

I just tried the following and it worked:

External file:

define( 'WP_USE_THEMES', false );        
require('wp-blog-header.php');       

do_shortcode('[displayshortcode]');

functions.php file:

function shortcode_function() {
     echo 'shortcode';
}
add_shortcode('displayshortcode', 'shortcode_function');
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top