WP shortcode outputs shortcode as text - php

I'm trying to use shortcode in post to display gallery but on website it puts out shortcode itself as text.I'm using
<?php the_content();?>
in php file.
Same shortcode works well with
<?php echo do_shortcode('[shortcode here]')?>
but in this case I need it to be shortcode in post editor.

No need to write PHP code and just put [shortcode here] in the WordPress Post Editor.

If you want to use short code in wordpress post editor then no need to write php code.
And if you want to user the_content() in any wordpress .php file then you need to write and follow code pattern.
for example (example of single.php)-
<?php
while (have_posts()) : the_post();
the_title();
the_content();
endwhile;
?>
Lets consider that you are on the checkout page, in the dashboard > Pages > Checkout Page you enter this [woocommerce_checkout] and
In page-checkout.php file of your wordpress you can write your custom code to make it work.
Here is an example of my custom code :
<?php
if (have_posts()) : while (have_posts()) :
the_post(); ?>
<div class="container">
<div class="checkout-page my-4">
<?php the_content(); ?>
</div>
</div>
<?php endwhile; endif; ?>
Sorry for bad English :-P

Try adding following code in your active themes functions.php
add_filter( 'the_content', 'do_shortcode' );

Related

Editable posts WordPress

I'm trying to create my own template in CMS WordPress. I would like to have live editable text on my page http://restaurant.g6.cz/. I want to create something like posts and edit them from the web, because I can't think of anything better. I tried to paste into (page.php) something like
<?php
$my_post = get_post(168);
echo $my_post->post_content;
?>
and tried edit the text with plugin Live Editor but I wasn't successful, so I tried to write
<?php query_posts('cat=5&showposts=1'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>
<?php wp_reset_query(); ?>
this was editable but every post needed it's own category. Does anyone know, how to do this in PHP or better way without plugins? Thank you all very much :)
Example

Adding content via wordpress admin

I'm developing a wordpress theme where I have a set of custom pages and each page has it's own content! For an example, say there is a custom page where the content is already done using HTML but I need to be able to change the content of a single paragraph using the wordpress admin panel.
How do i do this using the wordpress framework? is there any special way of adding custom editable fields to specific content locations in a page?
Just add meta box and get the values from post meta to show in your html
you can generate metabox from this site without any programing skills
https://jeremyhixon.com/tool/wordpress-meta-box-generator/
and get meta field value with the below code
get_post_meta(get_the_ID(), 'meta_key', true);
Use Wordpress loop to do this:
<div class="content">
<p>Your static content goes here</p>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif; ?>
<p>Or here</p>
</div>
This part between if(have_posts()) and endif; will be generated from Wordpress admin panel so you can easily change it with page WYSIWYG editor without any additional plugins.
Don't forget to create your custom pages as page templates and assign to page in admin panel otherwise it won't work as expected.
Use the following code:
<?php
$id=2;
$post = get_post($id);
$content = apply_filters('the_content', $post->post_content);
echo $content;
?>
Here, $id=2 is your page id which is you get from WordPress Admin panel.

Display WordPress posts on external webpage

I am running WordPress functions on an external webpage to get posts and pages. The functions work fine.
I am using
the_content();
to display the body of the posts but it doesn't seem to be keeping the correct formatting. The HTML is displaying fine, but the line breaks etc are not.
Here is the full PHP code i am using:
$page = get_page_by_id($_GET["p"], OBJECT, 'post');
query_posts('p='.$page->ID.'');
if($page->ID) {
while (have_posts()) {
the_post(); ?>
<h2><?php the_title(); ?></h2><br>
Posted on <?php the_date(); ?><br><br>
<?php
the_content();
}
}
Screenshot of my site: http://postimg.org/image/nc2xw6af3/
Screenshot of the Wordpress Template: http://postimg.org/image/r01znya1p/
Looks like the required CSS information is missing. You need to include the CSS for <h2> and <p> tags from the WordPress template.

Displaying varying Wordpress content using get_template_part

I'm working on a Wordpress landing page template and the way I want it to work is that each content-xxxxxx contains a different block of text/images etc. Then on the Front Page I can call them like;
<?php get_header(); ?>
<div class="container">
<?php get_template_part( 'content', 'featuredcontent'); ?>
<?php get_template_part( 'content', 'textblock'); ?>
</div>
<?php get_footer(); ?>
Which is great and works fine, but I want to be able to choose the order of the blocks from within WordPress without having to edit the front-page.php file, does anyone have any idea or code that can help with this?
Thanks

Show readmore in wordpress post

In wordpress Twenty Eleven theme how to show read more after one post without writing any <!--read more--> in post page
Go wordpress admin panel and click reading under reading, choose summary instead of full text. That will help you.
Dashboard --> Settings --> Reading and click on "Summary" instead of "Full text"
EDIT:
The above settings for feeds. for showing in the home page, While you adding post put your cursor where you want to add "more" tag and then click Alt+Shift+T or click the button left to spell checker it will insert a more tag on your posts. I think this might work..
use the_excerpt() function in your post and add filter excerpt_more and add readmore.. link.
here this blog uses same function which is develop by me [Latest smartphone apps][1]
[1]: http://latestsmartphoneapps.com here on index page all post summery is given and readmore.. link is given which then display full post.
If you want such functionality let me know.
Use this code for Excerpt.
<?php query_posts('cat=ID'.'&showposts=NO. OF POST') ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php the_post_thumbnail(); ?>
<p><?php echo substr(get_the_excerpt(), 0,65).' [...]'; ?></p>
Read More...
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<?php endif;?>
The a look at the_excerpt

Categories