简体   繁体   中英

Calling an external do_shortcode from a PHP file

Im trying to populate a DIV with an external do_shortcode from a PHP file on my server. But all i'm getting is a fatal error message

Basically there will be two buttons that when clicked will populate the DIV with different content based on two different PHP files.

Here is the html in my page_template.php and the javascript to populate the DIV

 <ul> <li><a class="ajax-link" href="template1.php">ONE</a></li> <li><a class="ajax-link" href="template2.php">TWO</a></li> </ul> <div class="page" id="main_content"></div> <script> $("a.ajax-link").on("click", function(e) { e.preventDefault(); $("#main_content").load(this.href); }); </script> 

template1.php and template2.php just has the do_shortcode php:

 <?php echo do_shortcode('[ff id="1"]'); ?> 

You can't output shortcode using ajax. Because when doing ajax request the admin-ajax.php doesn't know about shortcodes.php file. You don't have access to whole wp environment when request with ajax.

You can create two wordpress pages and add shortcode in that page and create a template without calling header and footer (But include CSS and JSS)

Page 1 - [ff id="1"]
Page 2 - [ff id="2"]

Assign Template to these pages in wordpress backend

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM