When I create a post using wp_insert_post() if the post_content contains an HTML link I'm getting a copy of the post_content in the <head> and the <body> of my post HTML page.

The strange thing is when I add an HTML img to the post_content it works fine. Any suggestions?

Here is my code:

In a nutshell, I have posts that I am using as templates. The template ID's are stored in an array called $array_of_post_templates and I run them through a foreach loop to get the post_title and post_content from each template and then insert that data into its own post using wp_insert_post()

foreach ($array_of_post_templates as $post_temp) {

            $query = $wpdb->get_row("SELECT post_title, post_content FROM wp_posts WHERE ID LIKE {$post_temp}");

            $post_title = $query->post_title;
            $post_content = $query->post_content;

            $arg = array(
                'post_type' => 'post',
                'post_title' => $post_title,
                'post_content' => $post_content,
                'post_category' => array($post_cat),
                'post_status'   => $pub_status,
                'comment_status' => 'closed'

            $new_post = wp_insert_post($arg);

Example of basic HTML link I am trying to insert:

<a href="https://google.com">Click Here</a>

1 Answer 1


After a little more debugging I realized the problem was being caused by another file in my plugin and the above wp_insert_post() code above is working correctly. I guess that explains why I couldn't find anyone else having this problem.

So the CORRECT ANSWER is... if you are working on a plugin and all else fails, try deactivating your plugin to see if the issue goes away.

On a side note, it's always amazing how sometimes just taking the time to type out your problem in question form helps you to solve your own problems. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.