WordPress.org

Ready to get started?Download WordPress

Forums

Black Studio TinyMCE Widget
[resolved] Adds unwanted p tag (2 posts)

  1. smayton
    Member
    Posted 1 year ago #

    This is probably something that's obvious, but...

    Since, my html tags are specified elsewhere, I don't need the default p tag that shows in the HTML view of the widget. If I remove this tag, switch to WYSIWYG, and go back to the HTML view, the p tag returns.

    Can I add an option under WYSIWYG Formatting drop down to "none" and/or remove the default formatting from within the plugin files?

    http://wordpress.org/extend/plugins/black-studio-tinymce-widget/

  2. Marco Chiesi
    Member
    Plugin Author

    Posted 1 year ago #

    Unfortunately the automatic p tag addition is a native feature of the editor.
    I can suggest 2 alternative solutions:

    1) Adjust your css for p tags inside widgets accordingly
    If you set the p tags with no margin and padding it shouldn't mess your layout.
    Example:

    .textwidget p {
      margin: 0;
      padding: 0;
    }

    Depending on your css, you may need to reset also a few additional properties.

    2) Remove phisically the p tag via filter hook
    You may use the filter widget_text to remove the p tags from the text.
    Example:

    add_filter('widget_text', 'my_widget_text');
    function my_widget_text($text, $instance) {
        //remove any new lines already in there
        $text = str_replace("\n", "", $text);
    
        //remove all <p>
        $text = str_replace("<p>", "", $text);
    
        //replace <br /> with \n
        $text = str_replace(array("<br />", "<br>", "<br/>"), "\n", $text);
    
        //replace </p> with \n\n
        $text = str_replace("</p>", "\n\n", $text);       
    
        return $text;
    }

    Note: the above code has not been tested and it's partially taken from here.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.