Created
September 25, 2019 08:22
-
-
Save erip2/1386874d6803cc02d445424a2d4b88ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter('column-content-wrapper', function($content) use ($trunk_show) { | |
// parse the trunk show content as HTML | |
$trunkShowDomDocument = new \DOMDocument(); | |
$trunkShowDomDocument->loadHTML('<?xml encoding="utf-8" ?>' . $content); | |
// create a new element to wrap the content | |
$wrapperEl = $trunkShowDomDocument->createElement('div'); | |
$wrapperEl->setAttribute('class','content-column-wrapper'); | |
$wrapperEl1 = $trunkShowDomDocument->createElement('div'); | |
$wrapperEl1->setAttribute('class','content-column-wrapper'); | |
// move the content after the second paragraph until the last paragraph to the new element | |
for ($i = 0; $i <= $trunkShowDomDocument->getElementsByTagName("p")->length - 5; $i++) { | |
$el = $trunkShowDomDocument->getElementsByTagName("p")->item(2); | |
$wrapperEl->appendChild($el); | |
} | |
for ($i = 2; $i <= $trunkShowDomDocument->getElementsByTagName("p")->length - 2; $i++) { | |
$el1 = $trunkShowDomDocument->getElementsByTagName("p")->item(2); | |
$wrapperEl1->appendChild($el1); | |
} | |
$el = $trunkShowDomDocument->getElementsByTagName("p")->item(2); | |
$el1 = $trunkShowDomDocument->getElementsByTagName("p")->item(2); | |
// insert the new element to the trunk show content. | |
$el->parentNode->insertBefore($wrapperEl, $el); | |
$el1->parentNode->insertBefore($wrapperEl1, $el1); | |
$output = $trunkShowDomDocument->saveHTML(); | |
return $output; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment