plugin development - add short code not working

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 t

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

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

Share Improve this question asked Dec 11, 2012 at 7:59 user1867912user1867912 31 silver badge2 bronze badges 3
  • The plugin is activated? – kaiser Commented Dec 11, 2012 at 8:07
  • yes the plugin is activated – user1867912 Commented Dec 11, 2012 at 8:08
  • Your shortcode cannot work in its current form due to the echo. – fuxia Commented Dec 11, 2012 at 9:00
Add a comment  | 

2 Answers 2

Reset to default -3

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/magic-plugin
Description: Magic Plugin performs magic
Version: 2.3
Author: Mr. Magic
Author URI: http://example/
*/

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

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742345590a4426478.html

相关推荐

  • plugin development - add short code not working

    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 t

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信