Question

I am new to wordpress, I am creating a plugin and for the short code, I am using the short code api. But when I insert this shortcode in my page, it displayes as it is, it does not display the required output. Can asny body tell me what i am doing wrong? Am I calling or creating the function on right place or not? Below is my code

function show_review() {
echo "this is a review form";
}
add_shortcode('urp_review', 'show_review');

I have created the file named as urp_functions.php in my plugin directory and created the above function. Any help will be appreciated

Was it helpful?

Solution

Your code seems Ok, but is your plug-in correctly installed? You have to upload your urp_functions.php in a folder inside the /wp-content/plugins/ folder and in your urp_functions.php file, you have to insert comments so it gets detected as a plugin. here is the example comment on WordPress codex :

<?php
/*
Plugin Name: Magic Plugin
Plugin URI: http://example.com/magic-plugin
Description: Magic Plugin performs magic
Version: 2.3
Author: Mr. Magic
Author URI: http://example.com/
*/

Then once you have done this, you still have to go inside your admin panel and activate the plugin! Have you done all this?

OTHER TIPS

A shortcode is not supposed to echo its content, it's meant to return it

e.g.:

function show_review($atts) {
    return "this is a review form";
}
add_shortcode('urp_review', 'show_review');

The function is attached to a filter, it filters/processes shortcodes/contents.

If you do an echo, it prints out your code before the content has finished being processed, nevermind displayed.

Perhaps an analogy will help:

Imagine you're eating small cakes on a plate. You go to pick one up and your stomach digests it before it's even an inch above the plate. It needs to follow the process, receive the food inside your body and pass it along to the next organ, rather than doing it the moment anything food related happens.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top