WordPress.org

Support

Support » How-To and Troubleshooting » Shortcode test leads to blank page

Shortcode test leads to blank page

  • Hey guys,

    I am trying to get a feel for shortcodes, but my test is not working properly. I want to to change [test] with <p>TEST TEXT</p>, but when I put [test] in the page editor, no text shows up.

    Here is what is in my functions.php:

    function test() {
      return '<p>TEST TEXT</p>';
    }
    
    add_shortcode('test', 'test');

    and then I have [test] as the only thing on the page. I am running on localhost, if that matters. Does anyone know what I am doing wrong?

    Thank you!

Viewing 15 replies - 1 through 15 (of 28 total)
  • function test( $atts, $content = null ) {
    return ‘<p>TEST TEXT</p>’;
    }

    add_shortcode(‘test’, ‘test’);

    It still comes out blank.

    Change theme and try.

    Why change the theme? Everything else works, its just the shortcodes?

    Why change the theme? Everything else works, its just the shortcodes?

    Your theme could have same function ‘test’, could have some function which won’t let you have your own shortcodes, could have function to disable shortcodes, coud have removing filter etc, and etc.

    It’s a custom theme. There is nothing to do with shortcodes up to this point.

    It’s a custom theme. There is nothing to do with shortcodes up to this point.

    Add this in your functions.php:
    add_filter('the_content', 'do_shortcode', 11);

    Still nothing

    Does anyone know what I am doing wrong?

    WPyogi

    @wpyogi

    Forum Moderator

    Test it on a default theme.

    It works on the default theme.

    WPyogi

    @wpyogi

    Forum Moderator

    So then there’s something in your theme as suggested above

    Your theme could have same function ‘test’, could have some function which won’t let you have your own shortcodes, could have function to disable shortcodes, coud have removing filter etc, and etc.

    This is my entire functions.php. What is causing the problem, then? This is the first theme I have ever made myself, so I really have no idea what is going wrong.

    <!--sidebar -->
    
    <?php
    
    /*if ( function_exists('register_sidebar') )
    
    // Sidebar Widget
    
    register_sidebar(array('name'=>'right-Sidebar',
    
    'before_widget' => '<li>',
    
    'after_widget' => '</li>',
    
    'before_title' => '<h3>',
    
    'after_title' => '</h3>',
    
    ));*/
    
    function test( $atts, $content = null ) {
    return '<p>TEST TEXT</p>';
    }
    
    add_shortcode('test', 'test');
    ?>

    Hello?

    I replaced the entire functions.php of the twentythirteen theme, and it works properly. I did the same with my custom theme, and it does not work:

    <?php function test( $atts, $content = null ) {
    return '<p>TEST TEXT</p>';
    }
    
    add_shortcode('test', 'test'); ?>

    So does anyone want to help out? Or…?

Viewing 15 replies - 1 through 15 (of 28 total)
  • The topic ‘Shortcode test leads to blank page’ is closed to new replies.
Skip to toolbar