I am creating a small plugin where I am creating a few shortcodes. I am using Classic Editor plugin.
Here is my code in Plugin.php:
<?php
/**
* Plugin Name: Simple Data Visualizer
* Description: Reads data from CSV and displays data in required format
* Version: 1.0.0
* Author: Subrata
*/
function evd_dreambig_shortcode() {
return 'Hello! Can you dream big?';
}
function register_evd_shortcodes() {
add_shortcode( 'dream-big', 'evd_dreambig_shortcode' );
}
add_action( 'init', 'register_evd_shortcodes' );
But when I put the shortcode in Post content as [dream-big]
, it is only rendering the tag, i.e. [dream-big] on post page rather than showing its content: Hello! Can you dream big?
I also took a different approach:
function evd_dreambig_shortcode() {
return '<h1>Hello! Can you dream big?</h1>';
}
add_shortcode( 'dream-big', 'evd_dreambig_shortcode' );
But this does not work either.
I am using a custom theme. I also tried by adding add_filter( 'the_content', 'do_shortcode');
in functions.php. Still no luck!
plugin.php
is the only file in my plugin directory.
What I am doing wrong?
the_content()
function?apply_filters( 'the_content', $post->post_content );
in single post page. Don;t don't why I am needing this.the_content()
, not$post
or$post->post_content
. Make sure you read the documentation on theme development: developer.wordpress.org/themes/basics/template-tags