1

For some purposes i want to have custom php file in my Wordpress that will output content from 3 plugins.

This is the PHP code in the file :

<div class="wrap">
<div class="sidebar1">
<?php dynamic_sidebar('sidebar1'); ?>
</div>
<div class="sidebar2">
<?php get_template_part('sidebar2'); ?>
</div>
<div class="sidebar3">
<?php dynamic_sidebar('sidebar3'); ?>
</div>

However, when i try to open / execute the file i get error like

Fatal error: Call to undefined function dynamic_sidebar() ...

i guess its because i have to include some files to make all the functions / classes available to the custom PHP file.

How can i run this file without errors ?

1

1 Answer 1

1

Andrew Bartel is on the right path, but the link doesn't quite do what you want.

For static PHP files to access WordPress core functionality you need to add this to the top of the PHP file:

define('WP_USE_THEMES', true);

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

(This code is from index.php in WordPress core)

Ideally though, you would want to create a WordPress Page Template in your theme or child theme with the custom PHP code.

2
  • 1
    Perhaps a page template would be more apprioriate
    – Tom J Nowell
    Dec 7, 2014 at 1:13
  • I was looking for a way to print products in a custom php file and this (including wp-blog-header.php) did the trick.
    – akinuri
    Sep 29, 2017 at 6:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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