Creating button next to “add media” that allows you to choose a single post

For WP versions before 3.5.0, use the media_buttons_context filter: add_filter( ‘media_buttons_context’, function($context ) { global $pagenow; if ( in_array( $pagenow, array( ‘post.php’, ‘page.php’, ‘post-new.php’, ‘post-edit.php’ ) ) ) { $context .= ‘<a href=”#” class=”button”>Button</a>’; } return $context; } ); For 3.5.0+, use the media_buttons action: add_action( ‘media_buttons’, function($editor_id){ echo ‘<a href=”#” class=”button”>Button</a>’; } ); Both … Read more

Menu is not visible in appearance

I have done a complete answer on this a while ago on SO. You can see the complete post here. For the sake of WPSE users, I have copied my answer from that post. I have not edited it, this post was originally about adding and displaying a nav menu to the footer, but the … Read more

Add custom field to media attachment image attribute in post editor

I wonder if you want to modify the HTML of the inserted image, with the image_send_to_editor or get_image_tag filters? If that’s the case, then here’s one example: /** * Add the data-ext-link-title and data-ext-link-url attributes to inserted images. */ add_filter( ‘image_send_to_editor’, function( $html, $id, $caption, $title, $align, $url, $size, $alt ) { if( $id > … Read more

Set “Display name publicly as” to be usernames by default

If you want this for all future users then hook into the user_register event and update it there. Pull the WP_User using get_userdata and wp_update_user info with the new display name. add_action( ‘user_register’, ‘wpse_20160110_user_register’, 10, 1 ); function wpse_20160110_user_register ( $user_id ) { // get the user data $user_info = get_userdata( $user_id ); // pick … Read more

Custom category order with get_categories

Exact order by category id on get_categories @EliChan, by using get_categories, I don’t think it’s possible to exact order by id if you use exclude. It is better if use include as parameter of ids order and orderby with value include. $args = array( ‘hide_empty’ => 0, ‘orderby’ => ‘include’, ‘include’ => array( 47, 44, … Read more

Multiple content areas per page

This sounds to me like a perfect use of Advanced Custom Fields “flexible content” feature to me. Flexible content fields allow you to define multiple layouts, and then add them to a page or post one by one, in any order or combination you need. Each layout can be a combination of text fields, images, … Read more

Removing jQuery migrate and working with dependencies

First part… OK, so in your theme/plugin you have: wp_enqueue_script( ‘jquery’ ); wp_enqueue_script( ‘scripts’, get_template_directory_uri() . ‘/js/scripts.min.js’, array( ‘jquery’ ) ); The first line, enqueuing jquery isn’t necessary – you put jquery as dependency in second line, so it will be included anyway. These lines inform WP that you want to enqueue given file as … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)