• When I edit a post I notice some have become full of span tags like
    <span></span><span></span>
    e.g. on https://www.evamusby.co.uk the first line of html right now is:
    <span></span><span></span><span></span><span></span><span></span>Welcome! If you are caring for someone with an eating disorder, you've come to the right place. This vast web resource?is packed full of
    I’m on WordPress 4.7.3 running Twenty Eleven Child theme

    My guess is this has been happening for the last couple of months only.
    When I remove them all, some seem to come back.

    For editing I am using WPEdit plugin. I have also had HTML Post Editor for a long time and have just de-activated it as it’s not useful to me).

    Please could someone suggest how to stop these <span></span>tags getting inserted?
    And any automatic way of removing all these <span></span> combinations from all my posts and pages?

    I’m not clever with this stuff so please would you use idiot’s language?
    Thanks so much

Viewing 7 replies - 1 through 7 (of 7 total)
  • AddWeb Solution

    (@addweb-solution-pvt-ltd)

    Hello,

    This is default functionality of editor.
    You need to remove default style of editor.
    For this you need to add following code in function.php file of your theme:

    
    add_action( 'after_setup_theme', 'editor_setup', 11 );
    function editor_setup() {
     global $editor_styles;
     $editor_styles = array();
    }

    Hope this will help you.

    Thanks!

    Thread Starter evamusby

    (@evamusby)

    Thank you so much for your help.
    So far so good, except that now the editor doesn’t give me the nice visual layout I used to have, which replicated the layout of the uploaded page.
    Is there a way of having the best of all worlds?
    It seems strange that the default style of an editor would keep inserting lots of <span></span> tags, so I wonder if there is something else?

    Moderator bcworkz

    (@bcworkz)

    Yes, that would be strange indeed. I’ve never seen empty span elements inserted into any of my posts on a very plain vanilla installation. It is not default behavior. I also do not see how a style sheet could insert content into the editor. Styles can add content on the fly, but not into the editor’s text view.

    That’s not to say the editor doesn’t alter content, courtesy of wpautop() and similar filters. I’ve never seen empty span elements added though, other than on occasions directly attributable to removing text in the visual view. Sometimes invisible HTML elements get left behind after doing this.

    This behavior must be due to some added functionality from your theme or a plugin. It can even be indirectly related to applied stylesheets. If certain stylesheets are not applied, then the spans do not get added. Instead of removing all editor styles, try removing any not added by your theme. That may be enough to stop the insertions while preserving your theme’s editor style that matches the site’s appearance. Dump out the global $editor_styles to determine which elements to unset in the added action callback.

    Thread Starter evamusby

    (@evamusby)

    Thank you for that, bcworkz. I am slow on this as I don’t edit often and doing a bit of trial and error.
    Also I’m not sure where to find the editor styles you refer to when you say “Dump out the global $editor_styles to determine which elements to unset”
    Is it somewhere in Appearance>Editor>Child Theme ?
    If it’s easy for me to tell me, then do, otherwise I might do more wait-and-see.
    Thanks!

    Moderator bcworkz

    (@bcworkz)

    No, it’s not that simple. It’s more like adding another little snippet like AddWeb’s. Still relatively easy. Add this to the same file:

    add_filter( 'update_footer', 'dump_editor_setup', 100 );
    function dump_editor_setup( $current ) {
     global $editor_styles;
     $current .= "<br>\n<pre>" . print_r( $editor_styles, true ) . "</pre><br>\n";
     return $current;
    }

    Then temporarily comment out AddWeb’s add_action line by adding two slashes in front:
    //add_action( 'after_setup_theme', 'editor_setup', 11 );

    This converts the line into a comment, taking the code out of play. We need to do this so we can see the original value of $editor_styles. Now when you go into the admin area, the content of $editor_styles will be “dumped out” at the bottom of each admin screen. If the styles are selectively loaded, nothing may appear until you go to the post edit screen.

    The phrase “dump out” comes from the PHP function var_dump(), which outputs the value of any variable passed to it. I actually used print_r() for output, which is very similar to var_dump(). Some PHP coders will say dump out this or dump out that as a debugging technique, meaning use var_dump() to generate output.

    Anywho, go to the post edit screen and copy the output at the bottom below the Thank you and version line. Paste into a text file for use in future comparisons. Temporarily deactivate all of your plugins, then go to the post edit screen and again copy the output to a text file. Is there anything missing in the second output that is in the first? Does your persistent span issue go away with plugins deactivated? Does the visual editor display still look OK? Restore your plugins.

    If there are any missing items and your editor display still looks OK, paste them here and I’ll tell you how alter AddWeb’s code to remove only those without removing everything.

    Looking ahead, if removing any styles from plugins do not help, it would mean it is your theme doing this. It may still be possible to remove certain styles to prevent the persistent spans while not affecting the appearance. Or the two may be codependent. TBH, I don’t understand how this is really happening. I’m merely going on the fact that removing styles solved it. I happen to know how to selectively remove elements. How that affects things I don’t know.

    Thread Starter evamusby

    (@evamusby)

    Thank you for your generous reply!
    I think I get the gist of it. But I’m lost at the first step: which file is it I need to edit? You wrote “Add this to the same file” and I’m not sure which one that is.
    Thanks!

    Moderator bcworkz

    (@bcworkz)

    I was referring back to AddWeb’s original instruction (my emphasis):
    > “For this you need to add following code in function.php file of your theme”

    That file ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Span tags keep getting inserted automatically’ is closed to new replies.