How to insert a span inside a search form?

If we look at the source code of get_search_form(), notice that before the form gets rendered, the search_form_format filter hook gets fired. We can use that to add another filter attached to get_search_form where the callback is dependent upon the format. add_filter( ‘search_form_format’, ‘wpse_259716_search_form_format’, 99, 1 ); function wpse_259716_search_form_format( $format ) { if( in_array( $format, … Read more

What is the recommended way to create plugin administration forms?

I personally just add a menu link and in the function for it handle the form. With $_SERVER[‘REQUEST_URI’] as the action. Example below. add_action(“admin_menu”, “menu” ); function menu(){ add_menu_page(‘Test form’, ‘Test form’, ‘manage_options’, ‘show_form’ ); } function show_form(){ if ( $_SERVER[“REQUEST_METHOD”] == “POST” ){ print “do stuff”; } else { ?><form method=”post” action=”<?php echo $_SERVER[‘REQUEST_URI’]; … Read more

How to HTML5 FormData Ajax

The action should be part of the data object: var formdata = new FormData(); formdata.append(‘name’, ‘This is Name’); formdata.append(‘action’, ‘plugin_save’); $.ajax({ url: ‘admin-ajax.php’, type: ‘POST’, data: formdata, contentType:false, processData:false, success: success, error: error });

How do we remove the H3 tag for the reply-title I.D

Today there is a native option to do this without hacking the core, or doing tricky filters with output buffer. You just need to use the filter ‘comment_form_defaults’ and edit the values from ‘title_reply_before’ and ‘title_reply_after’ key: add_filter( ‘comment_form_defaults’, ‘custom_reply_title’ ); function custom_reply_title( $defaults ){ $defaults[‘title_reply_before’] = ‘<span id=”reply-title” class=”h4 comment-reply-title”>’; $defaults[‘title_reply_after’] = ‘</span>’; return … Read more

Get post ID from wp_insert_post()

You’ll have to do this in two steps. First, you will create a post in the draft mode, using wp_insert_post(). The wp_insert_post itself will return to you the ID of the inserted post: <?php $new_post = array( ‘post_title’ => ‘Draft title’, ‘post_status’ => ‘draft’ ‘post_type’ => ‘my_custom_type’ ); $postId = wp_insert_post($new_post); ?> <form method=”post” action=”your-action.php”> … Read more

How to get current url in contact form 7

See this example on how to create and parse the shortcode in the contact form 7 to use it add [current_url] add_action( ‘wpcf7_init’, ‘wpcf7_add_form_tag_current_url’ ); function wpcf7_add_form_tag_current_url() { // Add shortcode for the form [current_url] wpcf7_add_form_tag( ‘current_url’, ‘wpcf7_current_url_form_tag_handler’, array( ‘name-attr’ => true ) ); } // Parse the shortcode in the frontend function wpcf7_current_url_form_tag_handler( $tag … Read more

Hide the term description on the term edit page, for a given taxonomy

You could target the edit form for the post_tag taxonomy, through the post_tag_edit_form hook: /** * Hide the term description in the post_tag edit form */ add_action( “post_tag_edit_form”, function( $tag, $taxonomy ) { ?><style>.term-description-wrap{display:none;}</style><?php }, 10, 2 ); Here you can also target an individual tag. If you need something similar for other taxonomies, you … Read more