How to use a WP Shortcode Outside WP?

8 replies
Hi Guys

I wonder if anyone could help me with this question:

I have a WP plugin that displays a list of most popular posts in a WP Widget. I want to display that list on the part of my site that is outside WP.

The Widget output can be accessed via a shortcode. So my question is: is there a way, perhaps using PHP, to make use of the WP shortcode outsite Wordpress?

Thanks in advance,

Will
#shortcode
  • Profile picture of the author bhuthecoder
    use this code

    PHP Code:
    <?php echo do_shortcode('[shortcode]'); ?>
    {{ DiscussionBoard.errors[4668412].message }}
    • Profile picture of the author Steve Diamond
      Originally Posted by bhuthecoder View Post

      use this code

      PHP Code:
      <?php echo do_shortcode('[shortcode]'); ?>
      That will work outside of a WordPress post, in a template file for example.

      But Will asked how to use a shortcode entirely outside of WordPress. This code certainly does not work outside of WordPress. It's a function defined by the WordPress core environment.

      Sorry, Will. You would have to instantiate or import a significant portion of WordPress in your page for this to work. You would be better off migrating the non-WordPress pages of your site into WordPress, if that's practical. Then you could use shortcodes.

      Hope this helps.

      Steve
      Signature
      Mindfulness training & coaching online
      Reduce stress | Stay focused | Keep positive and balanced
      {{ DiscussionBoard.errors[4669177].message }}
      • Profile picture of the author Will Edwards
        Originally Posted by Steve Diamond View Post

        That will work outside of a WordPress post, in a template file for example.

        But Will asked how to use a shortcode entirely outside of WordPress. This code certainly does not work outside of WordPress. It's a function defined by the WordPress core environment.

        Sorry, Will. You would have to instantiate or import a significant portion of WordPress in your page for this to work. You would be better off migrating the non-WordPress pages of your site into WordPress, if that's practical. Then you could use shortcodes.

        Hope this helps.

        Steve
        Hi Steve

        Appreciate your reply.

        I had actually dug about the WO codex before making this post so I had already seen the above code. As you say, no good outside WP (but thanks to bhuthecoder anyway ).

        As far as importing the pages, I have a large site with about 4,500 indexed pages in Google, all built by hand without a CMS, so that's not an option.

        Cheers,

        Will
        {{ DiscussionBoard.errors[4669809].message }}
        • Profile picture of the author Steve Diamond
          Originally Posted by Will Edwards View Post

          As far as importing the pages, I have a large site with about 4,500 indexed pages in Google, all built by hand without a CMS, so that's not an option.
          Well, it's not entirely out of the question. If the benefit to you is large enough to justify the expense, it would certainly be possible to automate a procedure along these lines:
          1. Scrape the content from each page.
          2. Create a corresponding page in WordPress.
          3. Create a permanent (301) redirect from the old to the new URL.
          The 301 redirects would preserve the benefit of your indexed pages. In fact, depending on how the existing pages are named, it might be possible -- with a clever WP permalink structure -- to duplicate the old URLs exactly. Then you wouldn't even need the redirects.

          Not a trivial effort, so it would have to be worth it to you.

          Steve
          Signature
          Mindfulness training & coaching online
          Reduce stress | Stay focused | Keep positive and balanced
          {{ DiscussionBoard.errors[4688411].message }}
  • Profile picture of the author bhuthecoder
    all pages are stored in same server ?and they are .html or .php ?
    {{ DiscussionBoard.errors[4669973].message }}
  • Profile picture of the author bhuthecoder
    check these tutorials

    Code:
    http://wpengineer.com/1038/embed-wordpress-functions-outside-wordpress/
    Code:
    http://php.about.com/od/advancedphp/p/html_php.htm
    {{ DiscussionBoard.errors[4669993].message }}
  • Profile picture of the author guavasofts
    The short code API can help to make your Editor more advance especially with the help of Short codes to insert external content to your posts or pages easily.
    {{ DiscussionBoard.errors[4690329].message }}
  • Profile picture of the author lordspace
    Hi,

    the scraping is not necessary.

    The short codes can be replaced no problem.
    I have built an open source software (free) which does SEO on the fly for old static sites and forums (phpbb) without hacking the source code. (works as a filter and transforms content).
    ...the way it was designed was that I can build modules and filters/plugins very easily. If anybody is interested send me a message and I'll send you a link.

    The question is do your short codes have to be retrieved from the wordpress installation ?

    e.g.

    [come_cool_short_code param1="value1"]

    if the short codes do not come from Wordpress then it should be easy to create a folder with static files e.g.

    come_cool_short_code will correspond to data/short_codes/come_cool_short_code.txt and you can have the replacement content.
    Signature

    Are you using WordPress? Have you tried qSandbox yet?

    {{ DiscussionBoard.errors[4695714].message }}

Trending Topics