Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
    
The plugin is activated? –  kaiser Dec 11 '12 at 8:07
    
yes the plugin is activated –  user1867912 Dec 11 '12 at 8:08
    
Your shortcode cannot work in its current form due to the echo. –  toscho Dec 11 '12 at 9:00
add comment

2 Answers 2

up vote -3 down vote accepted

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?

share|improve this answer
    
no my urp_functions.php file don't have comments :( –  user1867912 Dec 11 '12 at 8:10
    
@user1867912 I just asked you if you have activated your plugin. This means that you A) can see it in the plugins list admin page and therefore B) must have those comments to be visible. => HOW the heck did you activate it without the comments? WP extracts all needed data from those. –  kaiser Dec 11 '12 at 8:11
    
It might just have been a misunderstanding on what "activate" means. I think it has become clearer now... ;-) –  barakadam Dec 11 '12 at 8:12
    
@kaiser i mentioned in my comment that my urp_functions.php don't have these comments. Should i add these comments in my urp_functions.php file? –  user1867912 Dec 11 '12 at 8:13
2  
Why is this question marked as the answer in its current form. This is not the solution, it should not be marked as such –  Tom J Nowell Dec 11 '12 at 9:17
show 9 more comments

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.

share|improve this answer
1  
"Perhaps an analogy will help" ... +1 for being consistent in every place. –  kaiser Dec 11 '12 at 9:36
    
Who the hell downvoted this and for what reason (aside from being the right answer)? –  kaiser Dec 11 '12 at 10:38
    
"declares answer wrong, makes no attempt to explain why" –  Tom J Nowell Dec 11 '12 at 10:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.