No, there’s no need to use wp_set_current_user()
.
I was wondering how to fire
wp_head
action if single post by certain
users (either by user ID or username)?
You can use $post->post_author
to get the ID of the author of the post, and put the user ID list in an array, then just do in_array()
to check if the author ID is in the ID list. For example:
function hide_author() {
//global $post; // Instead of this,
$post = get_post(); // I would use this one.
// Define the user ID list.
$user_ids = array( 1, 2, 3 );
if (
$post && is_single( $post->ID ) &&
in_array( $post->post_author, $user_ids )
) {
?>
Your code here.
<?php
}
}
And that example would run only on single post pages and that the current post’s author ID is in the $user_ids
list/array.
Related Posts:
- Different favicon on different pages
- Display random categories on the front page (Finding and Editing Theme Functions)
- Is it possible to remove the “standard” post format?
- opening links in new tab using – add_filter( ‘the_content’, ‘make_clickable’);
- Modify search function in WordPress (TwentyTwelve)
- How to customize search result page title?
- Removing Unnecessary Text from Admin Menu without CSS
- Set default options for inserting media
- Default or Preset Content for Custom Post Types
- Remove tag on my RSS Feed
- Display WordPress Search
- How to add a rel attribute to images that contains their categories?
- Preferred Use of home_url()?
- Custom function for user register in wp?
- How to add iOS & fav icons to the theme?
- Delete pages and Create default pages for all new network sites
- Actions according to image type and size
- Trying to inject twitter metadata into using wp_head action in functions.php – get_the_excerpt() returns null
- Post thumbnail relative link and HTML modify
- Refactor create_function
- adding custom classes for tables
- How would go about if I just want a temporary function?
- How do I edit wp_head and/or functions.php to remove rss-feed which isnt used and dont validate?
- Remove the deleted users avatar from list
- How to call custom function from functions.php in site-wide template files?
- Customizer field value into functions.php variable
- wp_dropdown_categories and custom attribute
- str_replace function in theme
- is_customize_preview() like function to check if Customizer “Live Preview” in JavaScript
- Right way to update widget on dynamic new input field
- How to customly read JWPlayer’s “Playlist” items by using its “playlistid”?
- Passing a variable via wp_head and then calling it on the page
- Include default functions and methods
- Hard-coding custom menu elements for menu manager
- Twentyten Child Theme: header images display messed up in admin panel
- How can I modify all existing tags while keeping the urls themselves?
- IF Statement on Button to make it complete and “uncomplete” based on user action / click
- Gravity Forms Button Text
- Find resources dynamically loading and change or add to the url
- When sale price is 0.00 show only regular price
- Unable to login using username
- Word Press – Dynamic Content [closed]
- Insert image in WordPress with HTML5 tag and caption function
- how can I just add to parent theme function(s) instead of redeclaring whole the function
- Move Custom Fields on General Settings Page to New Location
- Skeleton Child Theme Add Icon Bar to Header Flex Grid
- Remove adjacent_posts_rel_link under 3.2?
- Condition OR for current user ID
- How to retrieve the current post’s generated featured image size?
- Auto Generated HTML source code formatting
- Custom Behavior when Adding New Custom Post Type in Dashboard
- Where do I store custom functions that call custom page template files?
- Why There Is No “get content by ID” Function
- Custom HTML markup
- Use a shortcode to display custom meta box contents
- Wp-query Order By problem
- Create custom function for hero image
- Randomizing wp_tag_cloud() in child theme
- How to append classname to body tag if guest user
- Where do I go to edit this area? [closed]
- Replace plugin function with a custom function?
- Problem with images URL after filter applying
- Function to replace comment’s accented characters before posting
- New checkbox in custom widget isn’t saving data
- Linking Javascript in functions.php file
- Function to echo (or display?) wordpress tags in the head section
- How do I find the code executed when wp_head() is called?
- colorbox not loading in
- How to replace ACTION url from original wordpress login form?
- Save_post – Warning: Cannot modify header information
- How to use WP conditional tag in a functions.php with OCEANWP Theme?
- Modifying a WordPress Plugin
- CF7 select value get to function and reciept value from function
- External api call and make global variable for any page visitor enters , page-home, page, single etc
- CSS style and app.js not loading
- Parent category as WOOCommerce Categories widget title
- Extend WordPress Audio Widget to accept HLS (.m3u8) URLs
- How would I correctly implement a new if statement in a child functions file?
- Woocommerce custom calculation function
- Remove all video attachment, both files and post/postmeta from database?
- Will dequeueing in child theme functions.php file prevent Google Fonts from loading?
- True email confirmation for registration (keeping unvalidated users from user table)
- Placing CSS/ JS into the header or footer (inline) – trying to apply to several templates
- Replace image attributes for lazyload plugin on image elements with specific class
- How To Show Shortcodes In WordPress Custom Fields?
- Edit meta fields from within template
- How to make an If Else on Excerpt Filter
- Get Value of Custom Field
- restrict access to specific urls on a specific period of time
- How to request login for user but not for bots
- functions.php / replacing div’s with new ones?
- Echo a div to header.php from functions.php
- Post variables not displaying correctly in custom function
- new to javascript – using in instead of functions.php, not loading correctly
- How do I add functionality to images?
- WordPress Custom wp mail template return full template
- How to crop image in WordPress with aspect ratio for any size of image
- post_row_actions filter from parent theme not executing in child theme
- Customizer cuistom CSS Priority ordre Issue
- Copy and Modified WooCommerce function is_coupon_valid [closed]