• When trying to print HTML it adds <br> on every line jump.

    So having this in PHP Code Snippets:

    echo '
        <li>
            <a href="">
                Test 
            </a>
        </li>
    ';

    Will result in this:

    <a href="">
    <br>
    Test
    <br>
    </a>

    How can we avoid it?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello @mrstevejobs ,

    We tested the provided PHP code snippet on our end, but we were unable to replicate the problem you described.
    Given that we didn’t encounter any issues during our testing, it’s possible that the behavior you experienced may stem from conflicts with other plugins or themes installed on your WordPress site.

    To troubleshoot the issue further, we recommend the following steps:

    -Deactivate Other Plugins: Temporarily deactivate other plugins one by one and test the HTML printing functionality after each deactivation. This process will help identify if any plugin is causing conflicts.

    -Switch to Default Theme: Temporarily switch to a default WordPress theme (such as Twenty Twenty-One) to see if the issue persists. If the problem disappears with the default theme, it indicates a conflict with your current theme.

    Please let us know if you require further assistance or if you have any additional information that could help us pinpoint the cause of the issue.

    Thanks and Regards,
    Anjali

    Thread Starter mrstevejobs

    (@mrstevejobs)

    I believe it is due to the wpautop option used by Gutenberg. Which seems to be adding <p> and <br> if not in there.

    Here’s another example you can try:

    <?php  
    echo "
          <a class='social-icon' >
              Test
          </a>
    ";

    This outputs:

    <p>Test<br>
    <a class="social-icon" >
    <br>
    Test<br>
    </a></p>

    Notice how it wrapped it in two <p></p> and added a couple of <br>.

    Can you reproduce this on the default theme TwentyTwentyThree on Gutenberg?

    The “solution” I found is to minify the output before printing it, so it will be a single line of HTML.

    • This reply was modified 1 year, 1 month ago by mrstevejobs.
    • This reply was modified 1 year, 1 month ago by mrstevejobs.

    Regarding the usage of the PHP snippet editor, it’s important to note that it doesn’t utilize Gutenberg. Therefore, when incorporating the snippet’s shortcode into a page/post within the Gutenberg editor, please ensure that the shortcode is added to the classic block for proper integration.

    Additionally ,to remove the wpautop filter you can add, remove_filter( ‘the_content’, ‘wpautop’ ); to the theme’s functions.php file. This action should prevent WordPress from automatically adding paragraph and line break tags to the content.

    If the issue persists despite these measures, we kindly request additional steps for replication, as we were unable to reproduce it on our end.

    Thanks and Regards,
    Anjali

    Thread Starter mrstevejobs

    (@mrstevejobs)

    ?please ensure that the shortcode is added to the classic block for proper integration

    What do you mean by this?
    How do I do it?

    The “shortcode” is basically a Gutenberg block, so not sure how to tell WP it’s a classic blog instead?

    Hello @mrstevejobs ,

    Both the shortcode block and classic editor block of Gutenberg should work seamlessly with snippet shortcodes without any issues. In the classic editor section, available shortcodes will be listed in the “Insert PHP Code Snippet” option, allowing you to add them to the section with just one click.

    Please review your code and let us know if the issue persists. Additionally, if possible, share screenshots for further debugging.Also, please check for conflicts with any other plugins, as I’ve already mentioned.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Getting added when echo line jumps’ is closed to new replies.