How To Creating Shortcode for a post in WordPress
This code use for you is to create a Shortcode in any function.php
file WordPress.
Shortcodes are easy to use dynamic content into your WordPress pages, posts, custom posts, and sidebars.
WordPress Many plugins and themes use shortcodes to add specialized content like contact forms, image galleries, sliders, and more.
Step-1 <?php function getShortcode(){ $args=array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => 0, ); $my_query = null; $my_query = new WP_Query($args); $city_arr = array(); if( $my_query->have_posts()) { while ($my_query->have_posts()) : $my_query->the_post(); $meta=get_post_meta($my_query->post->ID); the_title(); the_content(); endwhile; } } add_shortcode('Shortcode', 'getShortcode'); ?> Step-2 //Add this code your wordpress page. [Shortcode] // Use shortcodes in form like Landing Page Template. echo do_shortcode( '[Shortcode]' ); // Store the short code in a variable. $var = do_shortcode( '' ); echo $var;
Author: Learn Tutorials Point
We Well organized and easy-to-understand Interactive tutorials With lots of examples of how to use Tutorials WordPress, PHP, Bootstrap, Bootstrap 4, HTML, CSS, AJAX, jQuery, Woocommerce, Post, Database, Javascript, Theme, Responsive, Templates.
Trending Posts
Tags
ACF
Ading custom columns
admin
Bootstrap
Cart Price
categories
Change Price
class
Code
comments
Create
Creating custom post Type
CSS
current
custom
Customizing
Custom Post
Custom Post Type
Custom Taxonomy
database
Date
Fatch
form
function
HTML
Image
Install
javascript
jQuery
Menu
PHP
Post
Post Type
Price
product
responsive
Resular price
Single product
Table
taxonomy
Theme
Title
woocommerce
Wordpress
Wordpress Code