The first two tutorials on adding content to WordPress posts or pages comprehensively introduce how to use the filter to change the _content function to add content. We demonstrated how to add content to the post before and after WordPress. The second tutorial describes how to add default content to the word press editor. Feedback from two posts – how to add default content to WordPress editor and how to add content after publishing content to WordPress; A frequently asked question is how to add default content to the word press editor in a custom post type.
Add the default content to the custom post type editor. The post wants to modify the filter used in the post and add the default content to the WordPress editor to use the same content in the custom post type. Therefore, the purpose of this tutorial is to demonstrate how to add default content in the custom article type editor. If you do not use WordPress to customize the post type, it is the same as the home page or post by default, but you can create it yourself. Functions in WordPress topics. You can add it to the PHP file to create it, and there are wonderful tutorials. Describes how to create a custom post type without using a plug-in. You can easily follow the steps.
\/\/Njengah tutorial custom post type example
\/\/Hook
Add_action (\
\/\/Callback function
Function njengah_tutorial_cpt (){
$labels = array(
\
\
\
\
\
\
\
\
\
\
\
\
\
\
);
$args = array(
\
\
\
\
\
\
\
\
\
\
\
\
“capability_type”=>“page”,
\
\
\
‘supports’ => array( ‘title’, ‘editor’, ‘author’, ‘thumbnail’, ‘revisions’, ‘page-attributes’, ‘cust
om-fields’ )
);
Register_post_type (\
}
After you are ready to customize the post type, you must import the code added in the previous guide into the function file to add the default content to the WordPress post editor.
The code consists of filters, and the callback function contains content that must be added to the WordPress editor. The code is as follows: add_filter(‘the_content’, ‘add_content_after’);
Function add_content_after ($content){
$after_content = \
$fullcontent = $content . $ after_content;
$fullcontent returns;
}After briefly summarizing the summary steps of each step, please add the default content to the custom post type editor according to the following three steps:
Create a filter hook to filter the default_content and its callback function into the default content to be added to the custom post editor. To verify true \/ false, add if \/ else conditional statements to the callback function to ensure that they are in the custom post type. If you are in a custom post type and you are in other posts, such as pages, posts, and other custom post types, add content. Returns content without adding it. In the next step of adding the default content to the post type editor, we must find out whether it is on the custom post type screen in the callback function, otherwise we will not add content.
If the content is added to the content editor by default, then check whether it is in the content editor by default, and if it is not, check whether it is in the content editor by default. To determine whether it is a custom post type, you can use the following conditional statement to check whether it is in a custom post type:$ currentID = get_the_ID();
If (get_post_type ($currentid) = = \
\/\/Then perform the operation here.
}You can also use the global post object in the callback function of the previously shared code. You must:
Function add_default_content_to_cpt ($content, $post){
If ($post – > post_type = = \
\/\/Then perform the operation here.
}
}Code snippet for adding default content to the custom post type editor. Now, the complete code for adding default content to the custom post type editor must have the following filters and callback functions: add_filter( ‘default_content’, ‘add_default_content_to_cpt’, 10, 2 );
Function add_default_content_to_cpt ($content, $post){
If ($post – > post_type = = \
\/\/Content to add to the custom post type editor
$new_content = please log in and leave a message! Spam is not allowed. \
$fullcontent = $content . $ new_content;
$fullcontent returns;
}
$content returns;
}
The custom post type slug must be replaced with the corresponding slug added when registering the custom article type.
In a function file or plug-in
After adding this code, the content added to the custom post type must be visible, but cannot be displayed in other post editors, as shown in the image below. Add a closing filter to ensure that the default content can be added to the custom post editor, and the callback function is a custom post type with conditional statements (if \/ else or switch statements). Added content. This is a useful tip for WordPress developers or sites who want to add content under the custom post type of the current topic. Similar articles: how does woocommerce change the out of stock text? How does woocommerce delete or disable comments? How does woocommerce add text before the price? How does woocommerce programmatically add products to the shopping basket and improve the efficiency of website search and SEO by more than 30 If you don’t log in to the best WordPress search plug-in WordPress, how can you redirect users? Page redirection wordcommerce storeon topic how to create multiple category templates how to get the current WordPress product category WordPress how to get custom post type how to create product Wo programmatically How to delete or hide comments from the ocommerce custom post type? In the custom post type, how to create a page in WordPress by disabling comment programming, how to save an order hook using wordcommerce, how to move instructions under the image in wordcommerce, and how to obtain an order ID from wordcommerce Method of dynamically inserting default content in WordPress post editor woodpress paging code fragment [from simple to advanced] A deletion method has been added to the shopping cart message. WooCommerce