WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom shortcode for a tag throws an error (3 posts)

  1. mtphoto
    Member
    Posted 2 years ago #

    I'm trying to create a custom shortcode to produce XHTML break tags.

    The code below is everything in my functions.php file and previously did not give me any errors, after adding the parts to setup the shortcode, I received this error message after trying to save a WP Page with the [break] shortcode added.

    Screenshot for the error I received.

    <?php
    if ( function_exists('register_sidebar') )
    	register_sidebar(array(
    	'name' => 'sidebar',
    	'before_widget' => '<div class="sidebar-box">',
    	'after_widget' => '</div>',
    	'before_title' => '<h2>',
    	'after_title' => '</h2>',
    ));
    
    if ( function_exists('register_sidebar') )
       register_sidebar(array(
        'name'=>'blog widgets',
    	'before_widget' => '<div class="sidebar-box">',
    	'after_widget' => '</div>',
    	'before_title' => '<h2>',
    	'after_title' => '</h2>',
       ));
    
    // Function and shortcode to allow line breaks past the WordPress editor.
    
    function linebreak() {
      return '<br />';
    }
    
    add_shortcode('break', 'linebreak');
    
    ?>
  2. NateJacobs
    Member
    Posted 2 years ago #

    That error often means you have some extra white space at the end of your file. In this case the error is being triggered at line 36 of your functions.php file. Take a look here to learn possible ways to fix it.

    http://codex.wordpress.org/FAQ_Troubleshooting#How_do_I_solve_the_Headers_already_sent_warning_problem.3F

  3. mtphoto
    Member
    Posted 2 years ago #

    Thank you! The extra empty lines at end of the file were causing the problem and now the shortcode works like a charm.

Topic Closed

This topic has been closed to new replies.

About this Topic