On a php page in wordpress, I have a shortcode for an accordion, that consists of the following, and works perfectly:
<?php echo do_shortcode('[su_accordion]
[su_spoiler title="Feature Locations" style="fancy"] CONTENT GOES HERE
[/su_spoiler]
[/su_accordion]'); ?>
Within the accordion, I want to display an interactive map, which can be displayed using either a shortcode, or PHP. Both options are:
[show-map id='1'], or
<?php build_i_world_map(1); ?>
When I insert either of these into the accordion shortcode, the map does not display. However, outside of the accordion, the second option above (with php) displays successfully.
What am I missing in terms of including this in the shortcode for the accordion?
In your example your outer section should be like
<?php echo do_shortcode('[su_accordion]
[su_spoiler title="Feature Locations" style="fancy"]'. build_i_world_map(1) .'
[/su_spoiler]
[/su_accordion]'); ?>
In wordpress you should call do_shortcode() for shortcode calls.
<?php echo do_shortcode("[show-map id='1']"); ?>
do_shortcode() reference
this is an effective way to include a concatenating inside a shortcode function
<?php echo do_shortcode('[download url='.$next_attachment_url.']'); ?>
Related
I have a php script that reads a text file of 10000 urls one in each line. The script displays all the urls in a blog post. I want the page to be divided into 10 small pages to facilitate comfortabe browsing. So how to add a pagebreak using <?php wp_link_pages(); ?> function inside a post? Something like this:
<?php
echo "Hi, This is First Page";
wp_link_pages();
echo "Hi, This is Second Page";
?>
That isn't how wp_link_pages(); works. It only displays your the_content in pages if your the_content contains this tag <!--nextpage-->
sudo code
<?php
echo apply_filter ("the_content" , "Hi, This is First Page<!--nextpage-->Hi, This is second Page");
wp_link_pages();
?>
You might want to check out this question as to how to retain the page data if you are creating your own page content and not using the standard content area.
Wordpress PHP - need to retain nextpage paginating tag in custom query
When already in a php block, you can execute a function without opening another php block. According to the documentation, wp_link_pages(); should also be called without echo.
wp_link_pages();
Documentation:
https://codex.wordpress.org/Function_Reference/wp_link_pages
This works just fine:
global $post;
$total = substr_count($post->post_content, '<!--nextpage-->') + 1;
this has been discussed before however it's not working for me. As the shortcode seems to be a mix of regular and open-close shortcode. Or a combination of nested shortcodes.
// Use shortcode in a PHP file (outside the post editor).
echo do_shortcode( '' );
// In case there is opening and closing shortcode.
echo do_shortcode( '[iscorrect]' . $text_to_be_wrapped_in_shortcode . '[/iscorrect]' );
This is the shortcode I would like to display in my php template
[mk_page_section bg_stretch="true" full_width="true" padding_top="0" padding_bottom="0" sidebar="sidebar-1"][vc_column][mk_header hover_styles="5" logo="false"][/vc_column][/mk_page_section]
What I am trying to achieve is display my main navigation on a webinar page that doesn't use my themes header or footer.
Is mit possible to use it like this?
<?php echo do_shortcode('[mk_page_section bg_stretch="true" full_width="true" padding_top="0" padding_bottom="0" sidebar="sidebar-1"][vc_column][mk_header hover_styles="5" logo="false"][/vc_column][/mk_page_section]'); ?>
Or must it be a combination? totally lost here...
Why is the do_shortcode not working?
I have to use some WordPress short-codes for a project - but I want them in very specific places, and not in the main content. I need the client to just put them in specific Custom fields. Using ACF, I built a text field specifically for this.
// normal in-code use
<?php echo do_shortcode('[example_shortcode]'); ?>
// ACF field
<?php the_field('my_main_shortcode'); ?>
// ACF field in the do_shorcode
<?php echo do_shortcode( the_field('my_main_shortcode') ); ?>
This renders out [example_shortcode] on the page instead of what I would expect.
I'm guessing this is a standard PHP thing - and I don't know how to escape or concatenate it properly. EDIT - below using get_fields gets me closer...
THEN... with a more complex short-code
<?php echo do_shortcode( '[tf_listview imagesize="medium1" exclude="calendar-link,list-view-title" dateformat="D n.j"]' ); ?>
It breaks somethings like the image by adding "" - which could totally be the way the short-code was written / but basically - I haven't found a solution to using a short-code in a custom field like this.
Bottom line,
I'd like to write: <?php shit_out('my_annoying_shortcode'); ?>
Or something as close to that as possible. AND have it actually work.
Can anyone give me some more direction?
Since you're using echo, you need to use get_field(), which returns the custom meta value:
<?php echo do_shortcode( get_field('my_main_shortcode') ); ?>
I am creating a WordPress plugin where a user can specify a custom loop repeater based on the value of a textarea.
The idea is, a user can use a predefined repeater that ships with the plugin or they can build their own repeater by simply adding html + PHP to the textarea.
Example of a custom repeater:
<h1><?php the_title(); ?></h1> <?php the_excerpt(); ?> - <?php the_time(); ?>
The issue is when I echo/print the textarea value, the WordPress functions within the <?php ?> tags do not execute.
Is what I'm attempting even possible?
Let me explain further...
I am building an installable plugin based on my Ajax Load More script.
This plugin will be only used by site admins and for total control of the display of posts I want to allow them to create a custom repeater.
On the plugin settings page, I want to have a textarea where the admins can add whatever html/php code they want in order to customize the repeater.
My issue is how do I execute the PHP entered within the textarea on the frontend as echoing the value does not work.
Use eval function to change plain text to php code. More about it here
eval('echo "Hello world!"');
will print out "Hello world!" instead of 'echo "Hello world!"'
BUT what if i write to textarea:
die();
One way of doing this is to use the eval() function as Justinas says, but I would strongly recommend you don't use it as I have found it to be unreliable and problematic.
What I would recommend is to write the PHP code in the string you extract from the text area to a file and then include that file where you want the PHP to execute.
So, I would recommend running
<?php file_put_contents($file_path, $contents); ?>
whenever the text area is updated to update the file, then
<?php include_once($file_path); ?>
where you want the code on the front end.
Those wordpress functions will not work unless they are in the Loop, Here is a basic Loop:
<?php if(have_posts()) { ?>
<?php while(have_posts()) { ?>
<?php the_post(); ?>
<?php // custom post content code for title, excerpt and featured image ?>
<?php } // end while ?>
<?php } // end if ?>
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