PHP code example of unematiii / wp-shortcode-tree
1. Go to this page and download the library: Download unematiii/wp-shortcode-tree library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
unematiii / wp-shortcode-tree example snippets
$content = \WordPress\ShortcodeTree::fromString( $page->post_content );
$folder = $content->getRoot();
$documents = $folder->findAll( 'document' );
// Prepend 'My ' to filename
foreach ($documents as $doc) {
$doc->attr( 'name', 'My ' . $doc->attr( 'name' ) );
}
// Write content
wp_update_post(
array(
'ID' => $post_id,
// $content is automatically serialized from ShortcodeTree to a string
// when __toString() is called automagically
'post_content' => $content,
)
);