Archived topic
Something happens to my social icons on publishing
29 replies · Started by Randy on August 5, 2020
To clarify my question, at the moment, I think I need to find out where I can find the element IDs. I have both author boxes active, but both are showing up on every page. The PHP doesn't seem to be working yet. I've tried a couple different things for the IDs, but apparently, I have gotten it right yet.
Thanks!
Hi there,
When editing the Element in the Dashboard, you can see the ID in the URL. It should be the only number.
Let us know :)
Hmmm. That's what I thought. As far as I know, then, the code is correct. But, they're both being inserted after the content, as here.
Thanks!
Aside of the ID numbers being correct we also have the is_author() condition which can use ID, Nice Name and Nickname. These examples explain then well:
https://developer.wordpress.org/reference/functions/is_author/#user-contributed-notes
Thanks for the info. I've worked with this, but still have trouble.
I did some digging in myPHPAdmin and found my Nicename and I verified IDs and Nicknames. I also tried to make sure I followed the code examples you shared. But nothing has worked yet.
In case it helps, here's my current code (though I've tried all the variations in the examples) …
add_filter( 'generate_block_element_display', function( $display, $element_id ) {
//First Author
if ( 10317 === $element_id && is_author('6')) {
$display = true;
}
//Second Author
if ( 10331 === $element_id && is_author('5')) {
$display = true;
}
return $display;
}, 10, 2 );
Thanks!
A good way to test your conditions is to do this:
add_action( 'generate_before_header', function() {
if ( is_author('6') ) {
var_dump('hello');
}
} );
Does that output "hello" before the header on the author page you're targeting?
No, it doesn't, actually. Also tried Author ID 5. I added it as a new snippet in Code Snippets.
Not really sure what this means, other than the test failed. :-)
For what it's worth, I did add some code to the Dashboard, with the code at #8 on this page to "Add the User ID column" partly to see if it would work and to verify user ID numbers (it worked).
Try this snippet instead:
add_filter( 'generate_block_element_display', function( $display, $element_id ) {
global $post;
$post_author_id = $post->post_author;
//First Author
if ( 10317 === $element_id && $post_author_id = '6' ) {
$display = true;
}
//Second Author
if ( 10331 === $element_id && $post_author_id = '5' ) {
$display = true;
}
return $display;
}, 10, 2 );
Thanks for the suggestion. I was hopeful, but it wasn't successful, either.
After trying it, I thought I would take a shot in the dark and check with the webhost just to see if they thought there might be any conflicts in the setup. They didn't see anything or have anything to suggest. I was just glad they looked into it. :-)
Perhaps something like this?:
add_filter( 'generate_block_element_display', function( $display, $element_id ) {
global $post;
$post_author_id = $post->post_author;
//First Author
if ( 10317 === $element_id && 6 == $post_author_id ) {
$display = true;
}
//Second Author
if ( 10331 === $element_id && 5 == $post_author_id ) {
$display = true;
}
return $display;
}, 10, 2 );
Hmmm. This is interesting. The one thing I noticed with this latest code is that, while it didn't change anything on the individual post (still showing both author blocks), it only showed MY author block on the homepage/index, but it did even on the ones I didn't write. The previous code showed both author blocks on the index page.
The first code(s) didn't add the author blocks to the index page.
Thanks for all of your help. I certainly didn't know this was going to be such a chore. :-)
So you're showing the author boxes within archives as well? Not just within single posts?
Yes. On checking again, my author block appears at the bottom of every page -- including Contact, About, Archives, Subscribe. But on the single posts, both author blocks show up.
Can you try:
1. Removing any and all Display Rules from the actual Element.
2. Adding this code:
add_filter( 'generate_block_element_display', function( $display, $element_id ) {
if ( is_singular() ) {
global $post;
$post_author_id = $post->post_author;
//First Author
if ( 10317 === $element_id && 6 == $post_author_id ) {
$display = true;
}
//Second Author
if ( 10331 === $element_id && 5 == $post_author_id ) {
$display = true;
}
}
return $display;
}, 10, 2 );
Okay, I removed the one display rule I had (posts/all posts). This worked for the single posts for each author (yay!), but …
Here's what else is happening:
- My author block appears at the bottom of each page (About, Contact, etc.).
- My author block appears at the end of each post on the main index page, even for the posts written by my wife (but, it shows her block when clicking on the single post).
- When I click on her author page, it shows her block with each post.
Thanks! :-)