API JSON Data in WordPress

Here is some quick first draft code for populating a dropdown from the Google Font API, I do not know about the options framework so this will not deal with that. 1. Get an API Access Key from Google Your request will need a valid key, you can follow the instruction here on how to … Read more

Admin Menus – Name Menu different from first Submenu [duplicate]

The first menu item typically is the parent item and shares the name with that item, you can however manually update the entry directly in the $submenu variable, like so.. add_action( ‘admin_menu’, ‘jp_create_admin_pages’ ); function jp_create_admin_pages() { global $submenu; add_menu_page(‘Members’,’Members’,’manage_options’,’members’,’jp_handle_admin_members’); add_submenu_page(‘members’,’Membership Types’,’Membership Types’,’manage_options’,’membership_types’,’jp_handle_admin_membership_types’); $submenu[‘members’][0][0] = ‘All Members’; } That way your parent keeps the original … Read more

Theme Customizer – Dynamic CSS PHP File

@s_ha_dum is right, the ajax plugin api is the way to go. I ran into this issue myself with a dynamic js file I was generating a little while ago. Basically you would enqueue your style as follows: wp_enqueue_style( ‘dynamic-css’, admin_url(‘admin-ajax.php’).’?action=dynamic_css’, $deps, $ver, $media ); Then create a function to load your dynamic css file: … Read more

WordPress media upload “HTTP error”

I figured out how to fix my problem. In my nginx config file (/etc/nginx/nginx.conf) I added client_max_body_size 100m; at the end of the #Basic Settings in the http {} section. I hope this answer will help some of you and please tell me if there is any better solution to this problem.

Should I use wp_mail or PHP’s mail? [duplicate]

WordPress offers its own mailing system. I suggest you use that instead of PHP’s native mail. wp_mail accepts five arguments: wp_mail( $to, $subject, $message, $headers, $attachments ); So your code can be written this way: // Set the headers $headers[] = ‘From: ‘ . get_option(‘admin_email’); // Add the addresses to an array foreach($emails as $mail) … Read more

Adding Google Analytics code to the tag of specific pages

While you can add the snippet directly to header.php, a better choice is probably the wp_head action which should be triggered in any well-made, modern theme. Using this hook allows you to insert the snippet without actually modifying your theme. It might look something like this: function wpse_282929_conditionally_print_ga_snippet() { if ( ! some_conditional_tag() ) { … Read more

Get list of shortcodes from content

Here’s one way: You can look at has_shortcode() and find the parsing there: preg_match_all( “https://wordpress.stackexchange.com/” . get_shortcode_regex() . “https://wordpress.stackexchange.com/”, $content, $matches, PREG_SET_ORDER ); using the get_shortcode_regex() function for the regex pattern. For non empty matches, you can then loop through them and collect the full shortcode matches with: $shortcodes = []; foreach( $matches as $shortcode … Read more

Bare minimum to include in PHP file to use WP functions? [duplicate]

You want to include wp-load.php or wp-blog-header.php not wp-settings.php or wp-config.php directly. If you look at the code in wp-load.php you will see why. wp-load.php looks for wp-config.php in several different places, including one level above the rest of the install. If you include wp-config.php directly the script will fail if wp-config.php has been moved. … Read more