How do I restore my layout after markup update, without reverting the markup?
-
I am facing a challenge after the plugin developer changed the markup in an update, the span with the class “customeradtitle” has been removed both from the parent div (with the class “clientad”), and from the link (with the class “advads-edit-button”).
My goal is either to restore my layout via CSS, or to move back the span into the div and into the link at the time of page load by str_replace or by output buffering, or by a generic (WordPress level or Theme level) or plugin specific PHP filter.
The “book title” is actually my image ads title.
I replicated / isolated the issue in CodePen:
Before the update (correct layout):
https://codepen.io/any_formless/pen/WNpLyyjAfter the update (wrong layout):
https://codepen.io/any_formless/pen/YzZdLMRI am not sure what is the difference between PHP output buffering and str_replace. I have only experience with str_replace. But I cannot use such a filter in my case:
$string_to_replace = '</a></div><span class="customeradtitle">Lorem Ipsum is simply dummy text.</span>'; $replace_with = '<span class="customeradtitle">Lorem Ipsum is simply dummy text.</span></a></div>'; $html = str_replace( $string_to_replace, $replace_with, $html ); } return $html;
Because the span text is subject to change. If there would be a way for the str_replace to ignore the span text, then I could put it in such a plugin function, I am not sure it’s correct:
function move_span_back ( $ad ){} add_filter( 'advanced-ads-output-final', 'move_span_back', 10, 1 );
or I could put it in a theme function instead, or in a generic WP function for replacing sequences of HTML, those perhaps would look at the whole page markup, not only at that sequence.
But the plugin function would probably not be able to see the outhanging span, only the “cientad” div, which is the AD div, is that right?
Because the change is not supposed to be reverted for real on a deeper level, because it said to be a fix.
The actual sequence of HTML in question, after the update (the out-hanging span need to be back into the div and into the link, or a CSS fix):
<div class="clientad" id="utopi-1638227998"> <div class="advads-edit-bar advads-edit-appear"> <a href="https://mysite.com/wp-admin/post.php?post=9764&action=edit" class="advads-edit-button" title="Order #9763" rel="nofollow"> <span class="dashicons dashicons-edit"></span> </a> </div> <a href="https://x.com" rel="nofollow"> <img src="https://mysite.com/wp-content/uploads/2021/05/d9b80977fdfa1dc7c54ab2f8a59667d4-scaled.jpg" alt="" width="1748" height="2560" style=" max-width: 100%; height: auto;"> </a> </div> <span class="customeradtitle">Lorem Ipsum is simply dummy text.</span>
With CSS it seems impossible to get the original layout back, I tried floating and clearing, changing positioning, and it didn’t work out.
The clientad divs are yellow in the CodePens, those are the actual ads purchased (it’s a site in construction so nothing is purchased yet), and the purple blocks are pink, those are the dummy ads that can be purchased. It’s important that in the CSS fix if it exists the yellow and pink blocks maintain equal height, which is a fixed height, because their height need to match with elements in adjacent columns, and that the span gets back inot the yellow div, and that its height will be automatic, filling in all vertical space left in the yellow div, under the image.
But the CSS fix doesn’t seem to exist.
I don’t mind so much that there is no plugin-specific fix for this because I don’t want to alter the plugin code much, it seems easier to revert the HTML at page load, and it wouldn’t have the same implications than changing plugin code.
Does anyone know a generic PHP or WordPress filtering solution either with str_replace or via php output buffering, or maybe other solutions that I don’t know about, that would work?
I was told that developers change the markup quite often, how do people deal with that, usually, if it affects their original layout?
Thanks!
- The topic ‘How do I restore my layout after markup update, without reverting the markup?’ is closed to new replies.