Wordpress Easy Contact Forms integration via php - php

I am trying to get Wordpress Easy Contact Forms plugin to my page by adding it to a page via text editor by using following: [easy_contact_forms fid=1] and then echoing the page content with php:
<?php
$post51 = get_post( 51);
echo $post51->post_content;
?>
However it just prints [easy_contact_forms fid=1] instead of actual form.
How do I get the form via php instead of the text content?

that is because $post51->post_content hasn't had the shortcodes "executed".
try:
$post51 = get_post( 51 );
echo do_shortcode($post51->post_content);
http://codex.wordpress.org/Function_Reference/do_shortcode

Related

do_shortcode with Instagram doesn't work - Wordpress

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.

How to insert a WordPress plugin code using PHP

I have a gallery plugin that can be inserted into WordPress using the code [LBS id=xx].
How can I use this code in a custom PHP page, I need to insert this code into, using PHP?
echo do_shortcode( '[LBS id=xx]' );

Wordpress template Echo a php string

I'm working on a page template and I'm having trouble working out how I can echo a string of php. Basically I have set up a custom field inside Wordpress for the page called Slider Code, and it asks the user to paste in the slider code given to them so that the appropriate slider is displayed on the page. The slider code given looks like this: [soliloquy id="82"]
The custom field plugin gives me this code to use in the template to echo out whatever is in that field, which looks like this: <?php echo CFS()->get('slider_code'); ?>
In WordPress there is a php function called do_shortcode which enables me to use that code, so it would look like this: <?php do_shortcode('[soliloquy id="82"]'); ?> and the slider would be displayed. So is there any way I can merge that <?php echo CFS()->get('slider_code'); ?> string with the do_Shortcode string? If not, does anyone have any alternative solutions to this issue? I can only think of having to make separate page templates for each individual slider.
EDIT: I have just discovered that the do_shortcode function does not actually work at all with the soliloquy shortcode. It does give me the option of using this code: if ( function_exists( 'soliloquy' ) ) { soliloquy( '82' ); }. However, when I paste this code into the custom field as is, the <?php echo CFS()->get('slider_code'); ?> tag just echos out that text. If I wrap the code in the custom field in <?php and ?> it just comments the code out inside my inspector. How do I get around this?
Check this out.
$slider = CFS()->get('slider_code');
call_user_func('do_shortcode', $slider);
I don't understand why you can't just run do_shortcode(CFS()->get('slider_code')).
Ok. Then try this one. Paste this code in the template file.
<?php
if ( function_exists( 'soliloquy' ) ) {
soliloquy( CFS()->get('slider_code') );
}
?>
And for slider_code input just enter '82'. If you are unable to see what is the template file you have to paste the above given code, then try to see WordPress template conventions.

Getting WordPress Gallery to work in external PHP file

I am developing a custom site and I am pulling in data from a wordpress backend to display on my page. The page that I am developing is completely outside of the wordpress directory. So far I have figured out a way to get the content to display on my page, however if the content has a gallery in it, the gallery doesn't display correctly on my page. What I see is the shortcode text [gallery ids="35,29"]. I am assuming that I need to include some functions or some other files in order to get my page to render the shortcode correctly? Here is what I have in my file so far:
At the top of my file:
<?php
define('WP_USE_THEMES', false);
require('../wp/wp-config.php');
//get_header();
function get_content($id) {
$post = get_page($id);
$content = apply_filters('get_the_content', $post->post_content);
echo $content;
}
?>
then in the page I have the code to display the content:
<?php get_content(25); ?>
Can someone please help?
Use do_shortcode to allow the shortcode to filter through it's own handler's and functions. This will return the formatted content.
Replace 'get_the_content' with 'the_content' and running that through do_shortcode.

wordpress post/page content in code

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

Categories