How to limit the use of this script only on the Vendor profile view page?

Good day.

For example, in the functions.php file, I have some code that runs a script on all pages of the site:

function custom_profile_phone_script() {
    ?>
    <script>
    jQuery(document).ready(function($) {
        // We get the value of the phone number from the main block of attributes
          ...
    });
    </script>
    <?php
}
add_action('wp_footer', 'custom_profile_phone_script');

How to limit the use of this script only on the Vendor profile view page?
To define my static and normal pages, I mainly use functions:

if ( isset( $post->post_type ) && $post->post_type === 'vendor' ) 
if ( is_page('slug-page')

And I don’t know how to add a condition to the definition of the Vender view page, which is dynamic and is built on the basis of hivepress templates

Hi,

Please try using this condition: is_singular(‘hp_vendor’)

​I hope this is helpful to you.

function custom_profile_hide_phone_mail_script() {
    // 
    if ( is_singular('hp_vendor') ) {
        ?>
        <script>
             ......   
        </script>
        <?php
    }
}
add_action('wp_footer', 'custom_profile_hide_phone_mail_script');

Does not work with if ( is_singular('hp_vendor'). If without condition if ( is_singular('hp_vendor'), then the script works…

1 Like