2
votes

I'm currently working (on my localhost) on a new wordpress page which uses various shortcodes from a plugin. When I create a page within the wordpress dashboard and insert a shortcode in the HTML edit it works fine.

However, I have now created a new page from scratch (home.php), which I want to use as my start page and I want to call one of the shortcodes and it doesnt work. When I insert just the shortcode in html [the_shortcode] the file just returns this as text output. When I use

<?php echo do_shortcode(‘[the_shortcode]’); ?> 

the page show not output.

I'm fairly new to shortcodes, so I'm not sure what I'm doing wrong. Does the file perhaps need to sit in a specific folder to be able to call shortcodes or needs some importing of files?

With regards to folder locations I have tried both:

C:\MAMP\htdocs\newwordpresspage
C:\MAMP\htdocs\newwordpresspage\wp-content\themes\newtheme

and then called the file via my localhost address.

Could anyone please help how to successfully call the shortcodes?

<?php 
define( 'WP_USE_THEMES', false ); 
require( './wp-load.php' );
echo do_shortcode('[gd_advanced_search]'); 
?>
2
non wp pages? you want to access the wp features outside wp? - Thamaraiselvam
I meant with that that the php file I created from scratch in Atom was not created in the wp dashboard, but of course it lies within the wp folder (see root in original post) - AlphaX
I just tested, your code works. The PHP file has to be in the WP root folder (same level as wp-load.php). - brasofilo

2 Answers

0
votes

In php template/theme file you should use.

<?php echo do_shortcode('[the_shortcode]'); ?>
0
votes
define( 'WP_USE_THEMES', false );
require( './wp-load.php' );

add these lines in your home.php now you are able to use all WordPress functions in your file.

Following one is working fine for me I created a shortcode test_code and using this plugin [sc name="test_code"]

<?php 
define( 'WP_USE_THEMES', false ); 
require( './wp-load.php' );
echo do_shortcode('[sc test_code]'); 
?>