Is there a way to add an specific ID to the body of that post that it's created by that method?

The thing is, I'm creating a new post using this

 $new_page = array(
                'post_type' => 'page',
                'post_title' => $new_page_title,
                'post_content' => $new_page_content,
                'post_status' => 'publish',
                'post_author' => 1,
                'import_id' => 999999,

I do that to give special styles only in that page that it's generated when the plugin is activated. As i gave the id 999999 the counter when I create a posts starts from there, 100000,100001 and so on... which i thing it's not good, so, is there a way to give the body an ID and not only adding it in the class?

  • 2
    What's the problem that giving a post ID 999999 solves? Post IDs always increment, the database doesn't go back and fill in the gaps. Making it do that will mean major performance hits on saving and updating posts. Fundamentally you shouldn't need to hardcode post IDs in code, it's the magic number bad coding habit, use post slugs/names if you really have to – Tom J Nowell Feb 13 at 16:25
  • @TomJNowell exactly I dont want to give that ID, to the post, intead of it I want to give the ID to the body, is there any way? – Christian Feb 13 at 16:45
  • What do you mean by adding an ID to the body? – Cadu De Castro Alves Feb 13 at 17:05
  • @CaduDeCastroAlves when the page is generated, the body structure is something like this <body class="page-id-6" id="?????"></body> is there a way to add an ID in there?? – Christian Feb 13 at 17:33
  • 2
    Yes, you should edit the template file you want to change. It should be inside single.php, page.php or, maybe, header.php. – Cadu De Castro Alves Feb 13 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.