Customize existing menu item

Given that you want to include a picture in the wp_nav_menu output, your best bet is to use the wp_nav_menu_items filter, as suggested in the comments. This will allow you to do a search and replace on the html. add_filter (‘wp_nav_menu_items’,’wpse229358_filter_menu’); function wpse229358_filter_menu ($items,$args) { $search=””; // html string of button $replace=””; // html string … Read more

Autogenerate a Table of Contents

Sure. In your single.php or where you loop through the posts, start by getting the content: $content = get_the_content(); Then use a regex where you target anything within <h2> tags: $regex = ‘/<h2>(.*?)\<\/h2>/u’; And then use preg_match_all() to find all titles: preg_match_all($regex, $content, $table_of_content); This will create a multidimensional array, see: print_r($table_of_content); So you have … Read more

Are there any security risks when submitting data-attribute data through AJAX?

When dealing with submit forms, even if they are sent with AJAX, you must play by the Never trust user’s input rule. Every data-attribute can be changed, edited via Inspector. Your only trusted validation should be on the server side, as you did with: if ( isset($_POST[‘author_id’]) || is_numeric($_POST[‘author_id’]) ) Personally, I would inverse the … Read more