Programmatically adding raw HTML
-
Is there a programmatic way to add HTML to a post (or create a new post) and have the HTML left as is? (no converting new lines into <br> or <p>, no wrapping <img> in <figure>, etc.)
I have been trying with wp_insert_post but no matter what I try extra cruft gets added in. even inserting directly into the DB has not helped (nor would this be a good final solution). As soon as I open it up in the wordpress editor, modifications can be seen.
I’ve tried many things, but this is the base case of what I am trying to do while having wordpress leave my html as is.
function createPage($title, $src) { echo "Creating $title"; $content = file_get_contents(__DIR__ . '/vanilla/' . $src); // just loading the html from another file. html is safe/clean $content = updateMediaUrls($content); // updating media (images etc) urls to proper path. quite irrelevant. $array = array( 'post_tile' => $title, 'post_content' => $content, 'post_status' => 'publish', 'post_type' => 'page', 'post_author' => 1, 'comment_status' => 'closed', ); $page = wp_insert_post($array); return $page; }
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Programmatically adding raw HTML’ is closed to new replies.