Removing unnecessary wordpress files

If you don’t use any 3rd services such as XMLRPC | REST API | oEmbed | Windows Live Writer, removing those lines/headers doesn’t affect anything to your site. Those lines of code is the best way to archive what you want. To remove xmlrpc.php?rds, you need another line: remove_action(‘wp_head’, ‘rsd_link’); Put all of them in … Read more

Foreach insert query the best way

Additionally, you prepare the statement, use it, and then close it every step of the loop. That’s a lot of wasted effort. Prepare once, use for the loop, then close at the end. $event_notification = mysqli_prepare($conn, “INSERT INTO user_notifications (notification_sent_by, notification_sent_to, notification_message, notification_time, notification_status, notification_category, notification_category_id) VALUES(?,?,?,now(),?,?,?)”); foreach($datas as $data) { $id_cliente = $data[‘user_join_id’]; mysqli_stmt_bind_param($event_notification, … Read more

How to display related posts from parent category

Just change this one line: $cat_obj = $wp_query->get_queried_object(); $thiscat_id = $cat_obj->term_id; $thiscat = get_category($thiscat_id); $chi = array(); if (!empty($thiscat->parent)) { $parentcat = get_category($thiscat->parent); $categories_chi=get_categories( array( ‘parent’ => $parentcat->cat_ID ) ); foreach ($categories_chi as $key => $value) { $chi[] = $value->cat_ID; } $pare = array($parentcat->term_id); $ids = array_merge($pare, $chi); } else { $ids = array($cat_obj->term_id); } … Read more

Image upload via FTP to wordpress media library

You can upload your images to your host, and then use media_sideload_image() to upload each file. Let’s assume you upload all of your images to a folder named wpse, in the root of your WordPress installation: // Set the directory $dir = ABSPATH .’/wpse’; // Define the file type $images = glob($directory . “*.jpg”); // … Read more

Replacing the NavWalker dropdown element

You need to replace the end_lvl method of Walker_Nav_Menu as well. This is what you would need to add: public function end_lvl( &$output, $depth = 0, $args = array() ) { if ( isset( $args->item_spacing ) && ‘discard’ === $args->item_spacing ) { $t=””; $n = ”; } else { $t = “\t”; $n = “\n”; … Read more

Automatic Excerpt Not Working

It turns out my client added shortcodes to the beginning of the posts and the only thing I can think of is that the_excerpt was choosing what words to use from the content before stripping shortcode tags out, thus, returning a blank excerpt. Hope this helps someone in the future

WordPress Customizer not setting default value upon initial install?

I’ve managed to fix this by changing the operator on the ‘if’ statement: Original: ?> <style type=”text/css”> <?php if( get_theme_mod( ‘facebooklink_edit’ ) == ” ) { ?> #fb-footer-bg { display: none; } <?php } // end if ?> </style> <?php Updated: ?> <style type=”text/css”> <?php if( get_theme_mod( ‘facebooklink_edit’ ) === #fb-footer-bg { display: none; } … Read more

Insert After Second Paragraph Without Tag?

I need to stress that I think this is going to be very unstable and you may not always get the results you want, but in simple cases this should work. $content = apply_filters(‘the_content’, get_the_content()); $content = explode(“</p>”, $content, 2); // var_dump($content); // debug echo $content[0].'</p>’; echo ‘<div>Extra Content</div>’; if (!empty($content[1])) { echo $content[1]; }