WordPress.org

Forums

[resolved] How can I make sure a plugin processes my code? (8 posts)

  1. OM2
    Member
    Posted 5 years ago #

    I've got a plugin that I've written that acts on a short code
    The plugin expects a page ID as the argument and is something like this:
    [myplugin post=1]
    This work OK on its own

    But, how do I make sure this plugin is processed if I do other processing?

    For example, I'm playing around with creating a template that reads in page ID's
    After reading in the page ID's, I want to construct strings like [myplugin post=1]

    So, when the page or post is shown, then the shortcode for [myplugin post=1] should be triggered as it normally is

    Problem: I'm doing this and all I get printed is [myplugin post=1] :(

    How can I make sure that the plugin code is processed?

    Note: I want to keep the plugin code separate and independent - else I could just incorporate the plugin code

    Hope some of the above makes sense

    Thanks

    Omar

  2. vtxyzzy
    Member
    Posted 5 years ago #

    You probably need to apply_filters as shown here in the Codex.

  3. OM2
    Member
    Posted 5 years ago #

    thanks for the reply
    i'm a little confused as to how to use whats given on that page?

    i'm not sure what to filter and what to pass it to?

    can u give any further guidance?
    let me know

    thanks

  4. vtxyzzy
    Member
    Posted 5 years ago #

    Well, I think I am the one confused. Can you explain a little more what you are doing with the template? I thought you were generating shortcodes in your template but they were not getting interpreted. What happens in the template with the generated shortcodes? Are they inserted into the content?

  5. MichaelH
    Member
    Posted 5 years ago #

    As vtxyzzy not sure what you are attempting, but if you are trying to execute a shortcode in a template:

    <?php
    //formulate and execute a shortcode in a template
    // this could be used to get current page id  $page_num = get_query_var('page_id');
    $page_num = 7;
    $shortcode = '[myplugin post='.$page_num.']'
    echo do_shortcode($shortcode);
    ?>
  6. OM2
    Member
    Posted 5 years ago #

    thanks for the replies
    let me try and explain...

    i have a shortcode function to which i supply a page or post id:

    [myplugin post=1]

    separately, in a page, i want to supply a page id and create the above as output:

    echo "[myplugin post=".$myPageID."]"

    what i want is WP to execute the sort code and not just output [myplugin post=1]

    am i making any sense?

    thanks

  7. MichaelH
    Member
    Posted 5 years ago #

    Isn't that pretty much what my example does?

  8. OM2
    Member
    Posted 5 years ago #

    Isn't that pretty much what my example does?

    erm: yes u r right - sorry, i didn't read - only just re-read now
    works a treat!
    i did actually read about that function - but didn't fully realise what i could use it for
    thanks a lot! :)
    i thought i'd be stuck on this one forever

Topic Closed

This topic has been closed to new replies.

About this Topic