WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Short code outside page or post?

[Resolved] Short code outside page or post?

  • Hi

    How do I get a short code to work outside a page and post?

    I’m trying to use a short code [faq list name] and I don’t want it inside post or page! I want it to work in a seperate <div> that I use on specific pages, “hard coded”. Therefor it’s important to be able to use the short code without using the default editor.
    Is it possible and if how do I do it?

Viewing 14 replies - 1 through 14 (of 14 total)
  • To execute a shortcode, use something like this:

    <?php echo do_shortcode('[catlist id=1 numberposts=5)]'); ?>

    The above example uses a shortcode from the http://wordpress.org/extend/plugins/list-category-posts/ plugin.

    Thanks but I have tried this code

    <?php echo do_shortcode('[faq list standard]'); ?>

    and it only outputs ‘[faq list standard]’ and not the list itself?!

    By the way I’m trying to get a FAQ from Faq tastic to show.

    That would make me think the plugin doesn’t support shortcodes or the plugin is not active.

    If you continue this thread you will need to provide a link to download the plugin.

    Link to plugin: http://knowledgeconstructs.com/wordpress-plugins/faq-tastic/

    And the plugin is active and support Shortcodes cause I can use it INSIDE a post or page but not anywhere else?! It works fine when I use the shortcode through the visual editor.

    I use Thesis Theme which have ONE file to add custom content to the Theme. Everything else works exactly as I want.

    This is the code I use in the custom_function.php-file:

    function headbox() {
    if (is_home()) {
    	echo '<div id="headbox">';
    	echo '<h1>FAQ</h1>';
    	echo do_shortcode('[faq list Standard]');
    	echo '
    ';
    	echo '</div>';
    	}
    }
    
    add_action('thesis_hook_header', 'headbox');

    This output a nice box with the FAQ headline and the text “[fag list Standard]” and not the list.

    Might need to put that in your theme’s function.php file.

    Nope that did not do it either?

    Tried in some other theme specific files too, but the code doesn’t work anywhere else than on a page or posts?

    Any other ideas?

    Could be this code

    if (is_home()) {

    See Conditional_Tags

    Nope tried using only the code to show shordcode
    echo do_shortcode('[faq list Standard]');
    But this got me thinking if the shortcode only works inside the loop? Apperently this function call is outside the loop!

    Well shortcodes can work outside the loop.

    I’m really stuck here! I have tried changing theme, disable all plugins except FAQ tastic. But nothing seems to change the fact that the shortcode doesn’t work outside a page or post?!

    What code can this shortcode be depending of that only is runned inside a page or post? What do the default editor do with the shortcode?

    I used this code in a single.php outside the loop, using the WordPress Default theme and it worked as expected.

    <?php echo do_shortcode('[catlist id=1 numberposts=5)]'); ?>

    Maybe a chat with the faq tastic author is in order.

    Yes I have contacted them today. Will get back here and report my progress.

    Hi I got an answer from faq-tastic.com and this is a part of the answer:

    At the moment FAQ-Tastic only works in the editor as it wasn’t built to be placed outside of the core wp_content area..

    He also said that it may be implemented in the next version.

    I have now created a my own script that outputs a random question everytime the page is loaded.

    Thanks for your effort to help me!

    If you get a chance, share your solution script so others might profit from your experience. Thanks.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘[Resolved] Short code outside page or post?’ is closed to new replies.