Show content if the post belongs to a specific author

Rate this post

I would like to know if there is any way to enable a script for visitors if the post they visit belongs to a specific author.

It is a script that I want to include in header.php or in single.php, if the visitor goes to a post that belongs to James, show or enable the following script in the header:

<script src="/wpauthors/james.js"></script>



function authScript() {
    if(get_the_author_meta('ID' == 2) {  // 2 is James uer ID here
      echo '<script src="/wpauthors/james.js"></script>';
add_action('wp_head', 'authScript');

Add this to your functions.php. It should work. Haven’t tested this myself.

Leave a Reply

Your email address will not be published.

Back to top button