I'm using wordpress with Woocommerce and am trying to call the
<?php echo do_shortcode('[woocommerce_pay]'); ?>
shortcode from within a php page.
Problem is that it gives us this result: [woocommerce_pay] instead of actually "performing" the shortcode and showing us the payment form.
Has anyone encountered this before?
Be sure the shortcode is placed in the "Text" tab of the page editor instead of the "Visual" tab.
If you're calling it through PHP: <?php echo do_shortcode('[shortcode]'); ?>. If you're doing it this way, you can't do this within the "Text" tab of the page unless you've allowed PHP to run from within a page. You need to add the PHP to a template file.
Here is a reference: Wordpress Codex for Shortcodes
Related
I'm trying to insert an embed post of Instagram via code using do_shortcode function. This is the shortcode example that Instagram gives on the embed documentation:
[instagram url=https://www.instagram.com/p/bNd86MSFv6/ hidecaption=true width=320]
So I'm trying to call it like this:
echo do_shortcode('[instagram url=https://www.instagram.com/p/bNd86MSFv6/ hidecaption=true width=320]');
The result I'm having is like I was using only the echo function, the shortcode comes as plain text on the browser.
The page that I'm editing is the single.php. And I did a test using a contact form 7 shortcode, it works normally with do_shortcode.
Am I missing something?
Have you created the code for [instagram]? Please post this code for us.
Put this in your functions.php file:
function my_awesome_shortcode( $atts, $content = null ) {
echo "This is my shortcode";
}
add_shortcode( 'awesome', 'my_awesome_shortcode' );
now put:
echo do_shortcode('[my_awesome_shortcode]');
into your single .php file. What is the result? if you get
This is my shortcode
Then it is working, you can use this template to build your instagram one.
Are you trying to insert this code in your pages/posts, or a template file?
For pages/posts, all you need is:
[instagram url="https://www.instagram.com/p/bNd86MSFv6/" hidecaption=true width=320]
For template files:
echo do_shortcode('[instagram url="https://www.instagram.com/p/bNd86MSFv6/" hidecaption=true width=320]')
Since you are not using a plugin, the shortcode has not been defined. You can either use a plugin ( https://wordpress.org/plugins/simple-instagram-embed/ ) or define the shortcode using Mark's suggestion.
I am trying to use php echo shortcode into Wordpress but I can't figure out how.
I want to use this shortcode:
php echo $pack['download_link'];
To add a shortcode in worpress:
add_shortcode('tag','myfunction' ); this add the shortcode in wordpress
function myfunction {
//your code to run
}
In pages or post use [myfunction]:
in templates echo do_shortcode('[myfunction]');
Your question has already been answered in a previous post
In short, PHP code cannot run within a WP post without an associated plugin that will process the PHP shortcode.
I have wordpress page with the following shortcodes
eg
page1
[myshortcode id='1']
[myshortcode id='2']
[myshortcode id='3']
... etc
Another has
page2
[myshortcode id='4']
and another has
page3
[myshortcode id='5']
What I want to do is get a php list of all the shortcodes on any selected page, eg page2, with the paramaters, i.e. the id.
The reason for this is I am writing a plugin wrapper to take an existing shortcode off a page and 'ajax' it, as a link in the currently generated code refreshes the whole page.
So my question is, how do I get a list of used shortcodes with paramaters from a page, using php or jquery?
You should check this out: http://codex.wordpress.org/Shortcode_API
Apparently all shortcodes are listed inside the $shortcode_tags:
<?php
global $shortcode_tags;
echo "<pre>"; print_r($shortcode_tags); echo "</pre>";
?>
You should be able to use this to find the active shortcodes on a PHP page, I guess.
Everytime i try to add a shortcode into my Wordpress site it ends up merely displaying the code i add to the actual page. I've been pasting the code into the "text" area of the content section but still doesnt work.
Even when I paste inside of the header.php file I recieve the same result. For example.
I recently copy pasted the following code in header.php (as instructed by the plugin i downloaded)
<div class="headerslider"> <?php echo do_shortcode('[sp_responsiveslider limit="-1"]'); ?></div>
When I save a reload, I just get [sp_responsiveslider limit="-1"] appear in my website. This happens with all shortcodes i do.
Please help
It seems like the shortcode sp_responsiveslider isn't actually defined. Are you sure the plugin is installed correctly? If the plugin is installed correctly you can test to see if shortcodes are working on your WordPress installation. Paste the following in your functions.php file (add <?php to the first line if it's not already in the file):
function test_shortcodes()
{
return 'Shortcodes are working!';
}
add_shortcode('test_shortcodes', 'test_shortcodes');
This will create a new shortcode in WordPress. To test if shortcodes are working put the text [test_shortcodes] within a post and view the page with the post. When you load the page the shortcode tag should be replaced with "Shortcodes are working!". If this works, there is an issue with the plugin and it's shortcode.
If the test text is not displayed there might be a problem with your WordPress installation.
i am trying to insert a post/page into one of my themes files and it wont display shortcodes or php
i have created a page called home in the wordpress admin-paned and inserted into my code the following:
<div id="home_page"> <!-- echos the content from the page "home" id:43 -->
<?php $home_id = 43;
$home_page = get_page( $home_id );
?>
<?php echo $home_page->post_content; ?>
</div> <!-- end #home_page -->
and non of the shortcodes that i have in the page work.
i installed a php in post or page and tried useing php and it doesnt work.
when i insert
echo do_shortcode('[youtube_sc url=http://www.youtube.com/watch?v=Db3XGpt6nNU]');
directly into the code it works.
does anyone know y this happens?
thank you.
I got an answer in wordpress.stackexchange.com
I Quote:
You need to apply the filter the_content e.g.:
<?php echo apply_filters('the_content',$home_page->post_content); ?>
Also, you don't need custom shortcodes for youtube, just put the URL in the content (but not a hyperlink), and it'll be swapped out for a youtube player at runtime. No plugins or extra code needed thanks to oembed.
Thank You Tom J Nowell
The $home_page->post_content value is the exact post content as stored in the database. Echoing this does not give any of your shortcodes a chance to run.
You should use a "WordPress Loop" to display the content, as this sets things up to allow you to use template tags such as the_title() and the_content() - this will call the processing functions for shortcodes and other functions like wpautop() that "massage" post content for output.
If you don't want to use a Loop, you could output the content using
echo do_shortcode($home_page->post_content);
This will run the post content through the shortcode processor, giving the shortcodes a chance to run.
For more on how WordPress "massages" post content, you can look here: http://codex.wordpress.org/How_WordPress_Processes_Post_Content