Archived topic
Create Hook with Custom Display Rule
3 replies · Started by Rizki on October 6, 2020
Hi team,
Is it possible to create a hooks element with display rules only in articles written by certain people ? Because there are several authors on my blog.
Thanks.
Hi there,
its tricky but is possible with some PHP - so better question is what exactly would be the difference between each of the authors hooks ? As it may be simpler to create a single hook that outputs that content dynamically.
Hi David,
The difference is some promotion-related information. OK, how do I create dynamic content on single hook ?
Or maybe you can explain "some php" you mean ? I think I can understand it enough if it's not too complex / doesn't require too much custom, hehe.
For Dynamic content you can use Advanced Custom Fields create a new User field so they are displayed in the user profile.
To display that field in the hook would require a little PHP:
<?php
// Get the post author ID
$author_id = get_the_author_meta('ID');
// Get the custom field
$my_custom_field = get_field('custom_field_slug', 'user_'. $author_id );
// Display field
echo '<p class="custom-class">' . $my_custom_field . '</p>';
?>
This article goes into a lot of detail for creating User fields:
https://noface.co.uk/user-profiles-advanced-custom-fields/
For Display Rules to set different Hooks - Tom explains here:
https://generatepress.com/forums/topic/add-element-to-posts-by-specific-author/#post-1287561