[Resolved] Create Hook with Custom Display Rule

Home Forums Support [Resolved] Create Hook with Custom Display Rule

Home Forums Support Create Hook with Custom Display Rule

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1474186
    Rizki

    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.

    #1474207
    David
    Staff
    Customer Support

    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.

    #1474237
    Rizki

    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.

    #1474277
    David
    Staff
    Customer Support

    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

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.