最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugin development - add short code not working

programmeradmin2浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论