Toggle admin metabox based upon chosen page template

The best way to approach this situation is via JavaScript. That way, whenever the selected value changes, you can instantly hide/show the related metabox. Use wp_enqueue_script() in functions.php to load a custom JavaScript file in the admin area: add_action(‘admin_enqueue_scripts’, ‘my_admin_script’); function my_admin_script() { wp_enqueue_script(‘my-admin’, get_bloginfo(‘template_url’).’/my-admin.js’, array(‘jquery’)); } The script itself, which requires jQuery, simply hides … Read more

Disable dragging of meta boxes?

I had the same problem, and Google lead me here. Unfortunately none of these answers helped, but I ultimately figured out the answer, and it’s quite easy! First, enqueue a JavaScript file (I won’t rehash this process; there are many tutorials that can describe this process better than I). I hooked into admin_enqueue_scripts, and it … Read more

Admin Page Redirect

/** * Redirect admin pages. * * Redirect specific admin page to another specific admin page. * * @return void * @author Michael Ecklund * */ function disallowed_admin_pages() { global $pagenow; # Check current admin page. if ( $pagenow == ‘edit.php’ && isset( $_GET[‘post_type’] ) && $_GET[‘post_type’] == ‘page’ ) { wp_redirect( admin_url( ‘/post-new.php?post_type=page’ ) … Read more

How to restrict dashboard access to Admins only?

We can hook to the admin_init action and check if the user is an administrator by using the current_user_can() function to see if the current user can manage_options, which is something only an administrator can do. This code, when pasted into your functions.php file, will display a message when a non-admin tries to access the … Read more

“Too many redirects” ONLY when trying to access wp-admin page

I found a solution that fixed my issue. Sources: A.) https://sharpten.com/blog/2018/01/17/wordpress-stuck-many-redirects-error-loop-using-ssl.html B.) (Sublink within A) https://wordpress.org/support/article/administration-over-ssl/ Excerpt: Adding the following lines of code at the end of my wp-config.php file resolved the redirect conflict. if (strpos($_SERVER[‘HTTP_X_FORWARDED_PROTO’], ‘https’) !== false) $_SERVER[‘HTTPS’]=’on’;

How to use “menu_order” field for posts?

Apparently it’s as easy as: add_action( ‘admin_init’, ‘posts_order_wpse_91866’ ); function posts_order_wpse_91866() { add_post_type_support( ‘post’, ‘page-attributes’ ); } And then doing the query: $order_posts = new WP_Query(array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘orderby’ => ‘menu_order’, ‘order’ => ‘ASC’, ) );

adding custom stylesheet to wp-admin

According to WordPress Codex (here): admin_enqueue_scripts is the first action hooked into the admin scripts actions. Example Loading a CSS or JS files for all admin area: //from functions.php //First solution : one file //If you’re using a child theme you could use: // get_stylesheet_directory_uri() instead of get_template_directory_uri() add_action( ‘admin_enqueue_scripts’, ‘load_admin_style’ ); function load_admin_style() { … Read more

Adding Fields to the Category, Tag and Custom Taxonomy Edit Screen in the WordPress Admin?

I added new field ‘picture’ (input type file) to category with help of these add_action(‘category_edit_form_fields’,’category_edit_form_fields’); add_action(‘category_edit_form’, ‘category_edit_form’); add_action(‘category_add_form_fields’,’category_edit_form_fields’); add_action(‘category_add_form’,’category_edit_form’); function category_edit_form() { ?> <script type=”text/javascript”> jQuery(document).ready(function(){ jQuery(‘#edittag’).attr( “enctype”, “multipart/form-data” ).attr( “encoding”, “multipart/form-data” ); }); </script> <?php } function category_edit_form_fields () { ?> <tr class=”form-field”> <th valign=”top” scope=”row”> <label for=”catpic”><?php _e(‘Picture of the category’, ”); ?></label> … Read more

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