There is very little overhead to assigning couple of filters on hooks that simply won’t fire on front end.
In general it would be something like this:
add_action('init', 'admin_only');
function admin_only() {
if( !is_admin() )
return;
// filter assignemnts and such go here
}
Also create_function()
is not recommended for performance and some other reasons. It is better to use more modern Anonymous Functions, but for cases like this WordPress provides ready-made __return_true()
function.
Related Posts:
- Displaying the number of updates available in the Admin area
- Remove a menu item created by a plugin
- How to remove Customize from admin menu bar after WP 4.3
- Modify Admin Bar Link
- difference between add_object_page and add_menu_page
- Remove Menu Page Giving Error
- Print Dashboard menu name and link
- Logout hyperlink within a sub-menu
- Add Featured image column into wordpress admin on pages AND posts
- Change position of media in admin menu
- Move ‘current-menu-item’ class on #adminmenu li from Posts to Pages for Taxonomy Edit Screen
- Creating A New Admin Menu Tab For Theme Options
- How to change a specific admin label
- How to add publish/draft button in Admin Post Lists
- Which method is more correct for removing WooCommerce Extensions menu item?
- Hide certain post types from editors
- How to add next height number in Order Attributes inside the Add new page. [duplicate]
- add_role menu pages are not visible
- Function Reference for custom link in Admin Menu Management Page
- Adding a second email address to a completed order in WooCommerce [closed]
- Advantages and disadvantages of using automatic-feed-links
- Gettext details
- current_cat_ancestor Alternatives
- Add body class of category parent
- Roles & capabilities GUI that does not create separate table
- Why get_header() or get_footer() does not run twice if called in the same php file?
- Max file size not updating
- Create thumbnail on PDF upload with Gravity Forms
- How to override filter in child theme?
- Use Exact Image Size using add_image_size
- How can I tell when a user is logged in?
- Enqueue Style in Functions.php
- Different functions file for each site in multisite installation?
- jQuery plugin function is not a function
- Limit posts only on home page – ideally in functions.php
- Make Categories a Dropdown Menu in Media Library
- If is multiple page templates
- Loop (iterate) through Multi-Site sub-sites (blogs)?
- Proper way of using functions in action hook?
- How to properly add function called by action-hooked function to functions.php?
- Get Current User info using wp_localize_script, in functions.php
- How to add new embed handler not supported by oembed?
- How do I add Bootstrap and LESS to my migrated WordPress site?
- Stuck on maintenance mode
- How to display custom option field in woocommerce orders in admin panel?
- Best practices regarding the creation of custom widgets?
- How to remove style attribute in WordPress RSS output?
- Multiple Loops Meta Data
- Update user meta of author when post content is viewed
- How to stop wordpress from injecting hard-coded style into image attachments with captions
- If ACF field is empty show different value [closed]
- What is the text that appears beside the page titles in the list of pages in the WP admin?
- Two functions with different arguments and add_actions, but identical code
- How to fix get_the_category function returning incorrect slug?
- How i can put $_GET codes in function.php?
- Disabling visual editor on a specific post
- Is there a way to direct unregistered user to registration page when click a link?
- Auto log in hook is requiring a page refresh
- Testing for a shortcode using a function. 404 page throwing PHP Notice
- how to get the post ID from wp_insert_post
- How to get post revisions in my custom rest API? [closed]
- Possible to merge these two functions?
- The Capability to choose post/page template
- The_content and Preg_replace in loaded Iframe [closed]
- dynamic site link for future migration in echo do_shortcode()
- Hide tab Buddypress profile for visitors, not logged in users
- Add a mature content warning to first-time visitors
- Show Featured Image in else statement
- Function to check if custom page is used by page?
- How can I remove page titles without removing the link in the navigation bar in twentyeleven?
- Simplest Way to Build Custom Archives Page?
- Filter for replacing the WP_query object for a given category
- Custom user role still showing up after deletion, ideas?
- wordpress built-in Jalali date convertor
- WordPress Function Assistance with Loop
- Bizarre Child Menu Issue on WP Site
- Populate acf-field, depending on block name
- get variables data from functions.php to template wordpress (without global variables)
- Add Change role button for list of user in an event
- I am trying to set post terms to a custom taxonomy
- how to increase connection time
- Shortcode to insert default text and change one word throughout it?
- Classic TinyMCE messing up only Contributor’s HTML
- Reference multiple style sheets, clearing styles for permalink page, custom fields for css
- Add schema to Search result page’s body. Tried using is_search
- Drop down list code for sidebar
- Hide disclaimer from summary excerpts
- WordPress Javascript Widget jQuery Dependency Issue
- Open image size links in a page instead of direct image link
- Allow tags and attributes in post and pages content
- Function to get thumbnail img source
- Syntax for a function in order to get post’s title in JSON encoded response [closed]
- Comment Function
- WP Custom Comment Callback Not Responding
- Do something when user creates post (that’s pending)
- Add product to cart from functions.php
- How I can show short content with short tag
- How do i set global variable in a function in wordpress functions.php
- Working function() doesn’t execute when triggered by WP CRON
- post_row_actions filter from parent theme not executing in child theme