WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Short code outside page or post? (15 posts)

  1. Cakeregister
    Member
    Posted 5 years ago #

    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?

  2. MichaelH
    Member
    Posted 5 years ago #

    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.

  3. Cakeregister
    Member
    Posted 5 years ago #

    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.

  4. MichaelH
    Member
    Posted 5 years ago #

    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.

  5. Cakeregister
    Member
    Posted 5 years ago #

    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.

  6. MichaelH
    Member
    Posted 5 years ago #

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

  7. Cakeregister
    Member
    Posted 5 years ago #

    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?

  8. MichaelH
    Member
    Posted 5 years ago #

    Could be this code

    if (is_home()) {

    See Conditional_Tags

  9. Cakeregister
    Member
    Posted 5 years ago #

    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!

  10. MichaelH
    Member
    Posted 5 years ago #

    Well shortcodes can work outside the loop.

  11. Cakeregister
    Member
    Posted 5 years ago #

    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?

  12. MichaelH
    Member
    Posted 5 years ago #

    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.

  13. Cakeregister
    Member
    Posted 5 years ago #

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

  14. Cakeregister
    Member
    Posted 5 years ago #

    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!

  15. MichaelH
    Member
    Posted 5 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic