Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am making a simple HTML form in a plugin I am writing. I was thinking of using echo for all output, but I can't seem to control the formatting of the HTML outputted (for debugging, neat looking HTML, NOT talking about how the page looks to the user).

If I have an echo like:

  echo '<sometag>
      <otherTag>';

It generates HTML like:

 <sometag><br><otherTag>

So I changed the echo statement to:

 echo '<sometag>';
 echo '<otherTag>';

and got HTML like:

 <sometag><otherTag>

Lastly I changed the echo statement to:

 echo "<sometag>\n<otherTag>"

But then WordPress turns the \n into a <br>!

Is the only way to have nicely formatted HTML to output the text with HTML outside of php?

Or is there a way to get echo (or print) just output what I send it?

OK - I found some code that points to a 'why'. It appears to me that the makers of this theme are using wptexturize and wpautop on all shortcodes, likely assuming that all shortcodes are their OWN (button, ui widget) shortcodes, and having wptexturize work on the shortcodes helps with some theme settings. I can think of perhaps better ways to do this...

I am writing a plugin for this theme, and will not be editing the theme, so I think I will tell them to use the [raw] shortcode route.

Theme code from /themename/functions/shortcodes/setup.php

 <?php
 // Remove WordPress automatic formatting
 function theme_formatter ($content) {
     $new_content = '';
     $pattern_full = '{(\[raw\].*?\[/raw\])}is';
     $pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
     $pieces = preg_split ($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);

     foreach ($pieces as $piece) {
        if (preg_match ($pattern_contents, $piece, $matches)) {
            $new_content .= $matches[1];
         }
         else {
        $new_content .= wptexturize (wpautop ($piece));
         }
     }

     return $new_content;
 }

 remove_filter ('the_content', 'wpautop');
 remove_filter ('the_content', 'wptexturize');

 add_filter ('the_content', 'theme_formatter', 99);



 // Enable shortdoces in sidebar default Text widget
 add_filter ('widget_text', 'do_shortcode');
share|improve this question
2  
PHP/HTML questions should be asked on StackOverflow. –  Chip Bennett Feb 21 '13 at 18:28
    
I think that this is a wordpress problem, in that I just figured out that things are different if I switch themes. –  Tom Andersen Feb 21 '13 at 18:38
    
That doesn't make it a WordPress problem... –  Chip Bennett Feb 21 '13 at 18:39
    
So this is my first post here, I have about hundreds on stackexchange, and would be happy to move it, but this problem will only happen in wordpress installs of some themes. –  Tom Andersen Feb 21 '13 at 18:44
1  
Can you add to your question the specific, problematic code from the Theme? –  Chip Bennett Feb 21 '13 at 18:48

1 Answer 1

up vote 1 down vote accepted

If this is plugin code there is NO REASON the theme would make a difference. My guess is it's a server issue (outputting of /n) or a WordPress function that changes the /n into <br>

I would check wpautop() as I find that sometimes it's this functions fault. See this post on the WordPress.org forum for more.

share|improve this answer
1  
That should be true - unless the Theme is doing something it shouldn't be, like messing with post-content shortcodes, or doing other manipulation of post content, that would cause the observed breakage. –  Chip Bennett Feb 21 '13 at 19:23
    
@ChipBennett true true, I sometimes forget that there are bad themes out there :) –  BandonRandon Feb 21 '13 at 19:25
1  
As you can see from the theme code, I think you guys are right! –  Tom Andersen Feb 21 '13 at 19:29
    
If switching the theme changes the output, then it doesn't seem like a plugin is the logical conclusion. –  Jake Feb 21 '13 at 19:58
    
The theme makes the changes to code output by a plugin shortcode. –  Tom Andersen Feb 21 '13 at 20:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.