Conditional check for front-end which includes ajax

DOING_AJAX and WP_ADMIN (this constant is checked within is_admin() ) are defined in admin-ajax.php and set tro true. Both are not very helpfull in this situation. Add a parameter to your ajax request if the request come from the front-end: <?php function my_action_javascript() { ?> <script type=”text/javascript” > jQuery(document).ready(function($) { var data = { action: … Read more

WordPress – wp-admin subdomain

The folder location /wp-admin is hardcoded into wordpress in multiple locations. It is pretty problematic to modify the location. WordPress will always go to /wp-admin. There are ways around this, but their are many steps. You can forward a subdomain to www.mydomain.net/wp-admin but WordPress will still always go through www.mydomain.net/wp-admin. Here is a reference if … Read more

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

How do I remove a require_once admin panel from the parent theme from the child theme functions.php?

For cases where you want to require/include PHP files, but still allow child themes to replace those PHP files outright, then you should use the locate_template function. Example: Parent does this: locate_template( ‘admin/file.php’, true ); This finds the admin/file.php file in either the child or the parent theme, then does a require on it (that’s … Read more

How to Load Scripts and CSS for Admins Only When Editing or Adding Posts

you want to use admin_print_scripts-(page_hook) and admin_print_styles-(page_hook), so in your case: add_action(‘admin_print_scripts-post.php’, ‘call_my_function’); add_action(‘admin_print_scripts-post-new.php’, ‘call_my_function’); add_action(‘admin_print_styles-post.php’, ‘call_my_styles_function’); add_action(‘admin_print_styles-post-new.php’, ‘call_my_styles_function’);