G
G
Genri_Rus2019-09-15 20:03:06
css
Genri_Rus, 2019-09-15 20:03:06

Is there an analogue of the php function is_admin_bar_showing() for checking in js?

Let me explain the problem, the fact is that when loading data ajax, the modal window has certain styles registered
And here top: 0 is registered, but let's say top: 32px
There is one way out of this problem, create 2 different files and connect them in the case of the admin bar or without?
I'm more interested in the question, but can I somehow check in the frontend?
Let's say the admin bar is currently shown or not?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
T
twobomb, 2018-04-14
@twobomb

Type of such

O
Oleg, 2018-04-14
@politon

Gradient + shadow
But you have a texture there, so a picture.

V
Vladimir Brumer, 2019-09-15
@Genri_Rus

You can pass a function to js using wp_localize_script.
Example:
code in function.php

add_action('wp_enqueue_scripts','load_styles_scripts');
if(!function_exists('load_styles_scripts')):function load_styles_scripts(){
    wp_enqueue_script('click',get_template_directory_uri().'/js/click.js',array('jquery'));//подключенный файл скрипта в котором Вы хотите использовать функцию is_admin_bar_showing

    $IABS=array('IABS_Out'=>is_admin_bar_showing());
    wp_localize_script('click','IABS_In',$IABS);//передаем в файл скрипта функцию

}endif;

then you need to get the data in this script file
after we do what we want
Видео пример

A
Anatoly Kulikov, 2019-09-15
@anatoly_kulikov

No extra files and duplicates are needed, everything is very easy to do.
If I remember correctly, the admin bar has a unique id. Check if it exists on the page, and if it exists, you can either add an inline style or a modifier class.
That's all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question