wp_nav_menu not working correctly in my underscores theme

If found out that this is removing my menu: function add_menu_icon ( $items, $args ) { if ( $args->theme_location == ‘primary’ ) { $elements=”<li class=”custom-logo”>” . get_custom_logo() . ‘</li>’; $elements .= $items; $items = $elements; return $items; } } add_filter( ‘wp_nav_menu_items’, ‘add_menu_icon’, 10, 2 ); I still haven’t figured out why.

Handling PHP/HTML inside the output of a shortcode function

This is mostly working fine. You probably want quotes around your id in the window.superformIds array to ensure it’s a string. This is a bad way of going about this. With scripts and styles you want to avoid outputting them directly on the page wherever the shortcode is placed. Here’s a better method: add_action( ‘wp_enqueue_scripts’, … Read more

php preg_match with multiple patterns

I think this is what you are looking for if (preg_match(‘@^/((?!blog|tag)[^/]+)/(?:page/)?\d+@’, $_SERVER[‘REQUEST_URI’], $m)) { wp_redirect(“/$m[1]”, 301); } The regexp uses lookahead to make sure that the first match isn’t blog or tag. The ‘[^/]+’ part matches anything that isn’t a forward slash (/). (?:page/)? – Makes an optional match against ‘page/’ \d+ – Match against … Read more

How can I find the cause of a 500 server error?

Okay, here’s what I did. If this happens, hopefully this will work favourably for you. If this is disabled by default, enable wp-debug by changing the value from false to true. Check that you have enabled WP_DEBUG_LOG and WP_LOG_DISPLAY. Try refreshing the page and see what happens. Either using WinSCP or the terminal, go to … Read more

How to send a HTTP Post request using PHP Curl and WordPress

I managed to solve this by adding the following into my functions.php add_shortcode(‘my_shortode’, ‘my_function’); function my_function () { $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_PORT => “2222”, CURLOPT_URL => “http://11.111.11.111:2222/folder/query”, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => “”, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => “POST”, CURLOPT_POSTFIELDS => “<root>\r\n <something1>username</something1>\r\n <something2>123456789</something2>\r\n <something3>Hello</something3>\r\n</root>\r\n”, CURLOPT_HTTPHEADER => … Read more

Get post categories

You’ll need to echo back your results in PHP. foreach($category_detail as $cd){ echo $cd->cat_name; } Also you might want to consider putting something between each category. If you have categories/terms like Blue, Red, Green. Then how you are currently looping over them, it will print it back as: data-category=”BlueRedGreen” Hope that helps!!

Can not add admin notices from the edit_user_profile_update hook (notices not being displayed)?

WordPress redirects you back to the user-edit.php page upon successful user update, so while the admin_notices has yet been fired in your sulock_save_profile_fields(), the message (your custom admin notice) is never displayed because of the redirection. And one way to fix it, is by filtering the redirect URL via the wp_redirect filter: // In sulock_save_profile_fields() … Read more