I’ve just tested your code in a function hooked on wp_body_open
and it works:
add_action( 'wp_body_open', 'function_test' );
function function_test() {
$tittle="My new page";
$newPage = array(
'post_type' => 'page',
'post_title' => $tittle,
'post_status' => 'publish'
);
$post_id = wp_insert_post( $newPage);
print_r($post_id);
}
Where do you use this code ?
Related Posts:
- How do I get the current edit page ID in the admin?
- Does hooking into the same action multiple times drain memory?
- Apply custom role capabilities to administrator (without plugin)
- Different wp_mail_from and wp_mail_from_name for specific situations
- In a WordPress plugin, how do you output HTML code inside the DOM header? [closed]
- Linking thumbnail to full size image
- is_front_page not working in functions.php
- VERY new to coding – keep breaking site trying to add to functions.php
- Restrict user registration to emails on a single domain
- Preferred Use of home_url()?
- How to enqueue JavaScript for specific WordPress pages only?
- Passing HTML in WordPress Shortcode arguments
- Can I use require() function in a template file?
- Functions.php reverted to new one
- Exclude Empty Child Categories in Menu
- Get page slug and assign a variable within functions.php
- Convert User ID’s to User Names in a single.php file
- Custom roles can’t access to wp-admin
- How to specify which Gutenberg blocks are available in the editor for a page template
- Custom Shortcode, functions PHP WP_Query loop
- How to insert a text in all pages and posts before or after specific places?
- Add class or ID to any WordPress function
- How to filter out shortcode when displaying the_excerpt() in the loop?
- wpautop – disable tags, keep tags
- How to remove howdy dropdown menu content
- Change Admin Bar “Visit Site” URL
- exclude a category from a search on a specific page
- How do I pass arguments for multiple functions hooked to a single action?
- Manipulate Permalink
- Last updated date function
- Possible to display shortcode based on the category?
- is_customize_preview() like function to check if Customizer “Live Preview” in JavaScript
- How to set default archive image without overriding first attached image? [closed]
- Toggle User Roles with button
- Passing a variable via wp_head and then calling it on the page
- Load Woocommerce and WordPress Functions Outside
- How to make custom column Admin>Users sortable?
- Theme functions.php file auto delete everyday [closed]
- Two Types of settings in WP – The Doubt
- How to know which ajax file or function is called for action
- How to filter $content in shortcode function
- Custom Attachment Caption Fields
- Generating dynamic css into custom file [closed]
- How to call particular funcion when the check box is checked in plugin options page
- Difficulty with PHP function that displays a post’s format in WordPress
- Events: Check for other event with same start date and category [closed]
- Function coding error concatenating quotes I think
- Need print logo without any ID & class
- Can we create our own theme’s function.php?
- Not all CSS elements transferring via parent to child?
- Reset postdata not working on WP_Query in functions.php
- Filter nav menu items HTML tags and wrap inner text with span
- Show some menu sub items as dropdown under a menu item
- Set “woocommerce_is_purchasable” to false for specific “$product->is_stock_status”
- The correct way to add a JavaScript in the functions.php [closed]
- How to remove some item from WordPress Dashboard for user Author
- How to make a new function that includes a template
- Disabling Author Page only for subscribers
- Showing user profile data on front-end
- How to register a menu based on a ACF condition
- How to convert raw url to hyperlink?
- Split single-review.php to two parts
- Breaking up multiple words and inserting an image after first word
- get content from page through AJAX
- Why is this function crashing my wordpress installation? [closed]
- colorbox not loading in
- The work of WordPress Function update_post
- how can I change all wordpress media file url to custom cdn url?
- Changing the HTML of notices in WooCommerce [closed]
- Can I use ‘Featured Image’ as a hero image and a thumbnail?
- How to Override Page Template if URL matches query?
- Save_post – Warning: Cannot modify header information
- How to use WP conditional tag in a functions.php with OCEANWP Theme?
- Woocommerce Display Discount On cart
- Modify content inside post before first publish
- Pass an argument into a function to extract from array
- function class doesnt work
- how to remove a tag in the_category function
- Load CSS file conditionally
- my wordpress doesn’t save items to customized widget area
- Copying a widget class to functions.php results on a blank page
- No compression occurs on my jpegs after adding jpeg_quality hook to my functions.php file
- Changing the register url is not working
- Newest comments first not working
- Pass arguments to function class with do_action()
- How to a override parent theme page that has been included with require_once?
- Display most popular posts
- Database Query not working
- Can I use a function to return HTML and the result of another function?
- Excerpt length: get 2 paragraphs
- Remove heading tags on line break
- How to use WP_rewrite?
- Wp get archive only text not link
- can not call functions in function.php
- Add custom fields after post/page title
- Sort results by name & asc order on homepage
- What are the parameters are used in add_action and filters?
- I want to add the alt attribute to all the photos!
- Does functions.php apply to every page?
- Creating mixture of shortcodes to use in the visual/text editor