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.
Related
I have a wordpress site, with buddypress and Youzify plugins running.
I need to put the Activity Stream as it is on the page designated for that, and put inside another page.
I've tried to include the plugin template, but it won´t work. Because a lot of functions of the template return UNDEFINED
add_shortcode( 'activity_stream', 'activity_stream_func' );
function activity_stream() {
ob_start();
include '/wp-content/plugins/youzify/includes/public/templates/activity/index.php';
$output = ob_get_contents();
ob_end_clean();
return $output;
}
This is not the exact code that I used, it´s just the ideia.
I am trying to create a shortcode from a page that currently resides in the back end. The page has several acf fields as part of a form that creates a request. I would now like to have the same page on the front end. I have tried following the syntax of creating a shortcode from a function after reading about shortocdes, its api and doc and several different tuts online.
add_shortcode('create_requests', array($this, 'load_custom_wp_admin_style'));
^ The attempt above didn't work and I don't get any output when I include the shortcode in a new page.
You can notice that the function I am trying to use 'load_custom_wp_admin_style' returns a null value and uses hooks.
This is the file that contains the function.
Try to include file like below code. I checked your file according to me you need use the plugin url it seems like you are developing the plugin
wp_register_style('your_namespace', plugins_url('style.css',__FILE__ ));
wp_enqueue_style('your_namespace');
wp_register_script( 'your_namespace', plugins_url('your_script.js',__FILE__ ));
wp_enqueue_script('your_namespace');
Assuming that the page you want to display on the front end is a normal WordPress page - created in the pages tab, post type page.
Very simply you can just use the following PHP code to include it in a template:
<?php
$page = get_post(192994);
echo $page->post_content;
?>
If it needs to be a shortcode you can add this into your functions.php:
function output_page_function($atts) {
$page_id = $atts['page_id'];
if (!$page_id) return false;
$page = get_post($page_id);
return $page->post_content;
}
add_shortcode('output_page', 'output_page_function');
And include a shortcode where desired (with 'page_id' attribute)
[output_page page_id=192994]
If it's not a WordPress page, but an actual wp-admin screen, then this would be significantly more difficult/not possible.
A client has requested that I place an html file on their Wordpress site, but I'm having trouble accomplishing this. The html file contains custom css and javascript in addition to custom meta tags. So if I just copy and paste the contents of the file into a page, it will obviously conflict with CSS and JS loaded by Wordpress. I would like add an add_action function to recognize the page I want custom html on and then only load that and not any Wordpress or theme data.
This is as far as I have gotten on my own.
add_action('wp_enqueue_scripts', 'toggle_theme', 1);
function toggle_theme() {
global $post;
$slug = $post->post_name;
if($slug = 'dream-vacation') {
}
}
I have been able to recognize the page I want to customize, but I can't figure out how to make it a clean page and load up the custom html I need.
Stop loading the page with WordPress.
Delete WordPress page with /dream-vacation/ slug.
Save page as /dream-vacation/index.html
In the midst of Customizing my new Wordpress site I would like to add next and previous portfolio post buttons to the single portfolio post page, and I've found that I can easily do so by pasting the following code:
<div><?php previous_post_link('%link', 'PREV'); ?> | <?php next_post_link('%link', 'NEXT'); ?></div>
Somewhere in the single-flv_portfolio.php page.
The only problem with this solution though is that I'm only able to place the links/buttons in the "portfolio frame" so to speak, and not in the actual content of every single post, which I would like to, for layout purposes.
I've tried pasting the same code within the contents of a portfolio post, using the backend editor, but to no avail. Wordpress, or my specific template (Wizard) seams not allow me using php at all - not even for something small like echoing out the current year in a dynamic copyright function.
Is it possible to maybe create the next and previous portfolio post functions in a custom .php-file, and then call them with an html anchor tag, and if so, how would I go about doing that?
Try something like this in your functions.php file:
function my_next_previous_link($content) {
$content .= 'some html here';
return $content;
}
add_action('the_content','my_next_previous_link');
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