I have two cases for is_rtl
, one doesn't work the other does, but don't know why.
Case1: doesn't work
i define a variable to hold a value depending on is_rtl
, then var_dump
it within the admin_footer
hook, then the result becomes LTR
<?php
/*
Plugin Name: Test
*/
class A{
public function __construct(){
$option_name = is_rtl() ? 'RTL ': 'LTR ';
add_action('admin_footer', function() use($option_name){
echo '<pre dir=ltr>';
var_dump($option_name);
echo '</pre><br>';
});
}
}
$a = new A();
Case2: works
I define the variable inside the callable hooked to admin_footer
, so the result becomes RTL
<?php
/*
Plugin Name: Test
*/
class A{
public function __construct(){
add_action('admin_footer', function(){
$option_name = is_rtl() ? 'RTL ': 'LTR ';
echo '<pre dir=ltr>';
var_dump($option_name);
echo '</pre><br>';
});
}
}
$a = new A();
So why this happens because i need to load options depending on the page direction, but can't get it to work.
I have two cases for is_rtl
, one doesn't work the other does, but don't know why.
Case1: doesn't work
i define a variable to hold a value depending on is_rtl
, then var_dump
it within the admin_footer
hook, then the result becomes LTR
<?php
/*
Plugin Name: Test
*/
class A{
public function __construct(){
$option_name = is_rtl() ? 'RTL ': 'LTR ';
add_action('admin_footer', function() use($option_name){
echo '<pre dir=ltr>';
var_dump($option_name);
echo '</pre><br>';
});
}
}
$a = new A();
Case2: works
I define the variable inside the callable hooked to admin_footer
, so the result becomes RTL
<?php
/*
Plugin Name: Test
*/
class A{
public function __construct(){
add_action('admin_footer', function(){
$option_name = is_rtl() ? 'RTL ': 'LTR ';
echo '<pre dir=ltr>';
var_dump($option_name);
echo '</pre><br>';
});
}
}
$a = new A();
So why this happens because i need to load options depending on the page direction, but can't get it to work.
Share Improve this question asked Jun 4, 2019 at 2:26 MakiomarMakiomar 1517 bronze badges1 Answer
Reset to default 1Case 1 - is_rtl()
is not working because it has been called directly. To use such contditional tags in WordPress, query should already be run. So such function should be used inside the function hooked to appropriate hook. Since it is called directly, its value will be always false.
See https://developer.wordpress/themes/basics/conditional-tags/#where-to-use-conditional-tags
Case 2 - It is working because you can using this tag inside the function hooked to admin_footer
. So, is_rtl()
will give you appropriate value.
So, if admin_footer
is not working for you then, you need to check which hook is appropriate for you and use is_rtl()
inside the function hooked properly.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745440109a4627791.html
评论列表(0条)