2

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]'); 
?>
3
  • non wp pages? you want to access the wp features outside wp? Commented Jan 7, 2018 at 19:07
  • 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) Commented Jan 7, 2018 at 19:39
  • I just tested, your code works. The PHP file has to be in the WP root folder (same level as wp-load.php). Commented May 30, 2021 at 3:09

2 Answers 2

0

In php template/theme file you should use.

<?php echo do_shortcode('[the_shortcode]'); ?>
Sign up to request clarification or add additional context in comments.

5 Comments

I did! I just noticed that it was deleted from my original post, probably because I didnt wrap it in the right format - see again pls, I updated
I noticed that you have put " ‘ " at place of " ' " in your shortcode function . Please copy and paste line from my answer.
For a second I hoped that would be it, but it didnt have any effect. I have again tried and saved the file in both locations and opened it via my localhost address. The odd thing is also that when i look at the source code (when I load the page) the code stops where the php line is inserted. Would you have any other solution idea? Thank you vey much for helping!!
I think now your shortcode is working. Can you check "the_shortcode" which I think you have defined in functions.php . May be there is any error in the function.
the shortcode itself is fine, because when I create a new page via the wordpress dashboard and edit the html code to insert the shortcode it works fine, i.e. it runs the function. However, I dont want to create a page there (which is only for blog entries or content in general). Do I have to save the php page in a specific location or include anything specific in the php file? I'm losing my mind with this ;-)
0
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]'); 
?>

4 Comments

Thank you! I amended the php to include this (see EDIT 1 in original post) but it didnt change anything. Does the file maybe need to sit in a specific folder?
check my answer i think you need to add prefix of that plugin which you used to create shortcode
The shortcodes from the plugin should not require any prefix (also I wouldnt know which ones), see wpgeodirectory.com/docs/core-shortcodes Shame, I cant get it to work. Is there anything else we could try?
Did you fixed the issue?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.