• Guys,
    I think my issue is too simple for many of you but I just started on wp and I have some programming experience (not much), anyway, I am too new and I need a little help from any of you.

    I create a very simple plugin for testing, in the page i just add the shorcode [aoq_action], and it is suppose to write just one time whatever is in the function HOWEVER the problem that I have is that the function is displayed in two parts, what appears to be on the top of the page (where the header banner is) and the other is showed properly on the page, down after the title. I tried and tried to see other scripts but even tutorials but nothing change. I was able to open a database and diplay whatever I want using the code but I am still have the same issue, the results is displayed on the top of the page (i think the header) and the other is displayed properly on the page.

    I think this is too simple for many of you but I need help. Maybe if you can tell me how to place it in the spot. Below the simple plug in…

    <?php
    /*
    Plugin Name: AO Product Query
    Plugin URI: http://xxx
    Description: This is simple query to bring my products
    Author: ao
    Version: 1.0
    Author URI: http://xxx
    */

    function f_action()
    {
    echo “<h1>this is a test</h1>”;
    }

    add_shortcode(‘aoq_action’, ‘f_action’);

Viewing 9 replies - 1 through 9 (of 9 total)
  • Yea that’s fine, I just copied it into a test site and gave it a try on a post and did a echo do_shortcode('[aoq_action]'); in a template file. Maybe a theme issue? How are you using the shortcode? You’re wrapping it in [] right?

    Thread Starter jaop73@hotmail.com

    (@jaop73hotmailcom)

    yes, Andrew, I dont know what could happen but I am changing also themes and the same issue I got. for testing purposes, what theme do you think i could use to test it….?

    Always, always use the default theme that comes with WordPress to rule out other issues, and without any other plugins too. In this case, 2012.

    This was a lesson I learned the hard way after banging my head against the wall for a couple days several months ago.

    Also I added a closing ?> tag, I don’t think that would make a difference but..

    shortcodes must not echo the output, but return it.

    http://codex.wordpress.org/Shortcode_API

    this should work:

    function f_action()
    {
    return "<h1>this is a test</h1>";
    }
    
    add_shortcode('aoq_action', 'f_action');
    Thread Starter jaop73@hotmail.com

    (@jaop73hotmailcom)

    Thank you, I changed to return and it is working now.

    Thank you so much….

    Thread Starter jaop73@hotmail.com

    (@jaop73hotmailcom)

    dear alchymyth,
    returning one line works, but when I tried to return other lines, per example,

    function f_action()
    {
    return “<h1>this is a test1</h1>”;
    return “<h1>this is a test2</h1>”;
    return “<h1>this is a test3</h1>”;
    }

    add_shortcode(‘aoq_action’, ‘f_action’);

    only return only one…. How I can do to return multiple lines… I know this is too simple for you but a little help will be great….

    you could concatenate the various outputs into one string and return that at the end of the function;

    example:

    function f_action()
    {
    $output = "<h1>this is a test1</h1>";
    $output .= "<h1>this is a test2</h1>";
    $output .= "<h1>this is a test3</h1>";
    return $output;
    }
    
    add_shortcode('aoq_action', 'f_action');

    shortcodes must not echo the output, but return it.

    Can’t believe I missed that in the OP’s first post 🙂

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Simple help’ is closed to new replies.