What gettex method can i use for the class names in wordpress theme?

Hello friends,

I have a little confusion with the gettext and escape methods. I want to put a class in a wrapper if a redux framework option is true or false.Like:

if($theme_options['opt-columns'] ==  true){
echo 'col-xs-9 col-lg-9 col-md-9';

Do i need to put esc_attr__() ? If do so how do need to put textdomain. Please elaborate as i have didn’t find anything on internet. Thank

esc_attr__ should be used for escaping variables / dynamic data
‘col-xs-9 col-lg-9 col-md-9’ is obviously not a variable

Also, your IF clause should look more like this:

if ( ! empty( $theme_options['opt-columns'] ) && true === $theme_options['opt-columns'] ) {

Learn to write nice and bullet-proof code.

Also, you should not use theme options (that’s pretty outdated way to manage options). Use WP Customizer instead (there are 3rd party frameworks for that, like Kirki for example) and retrieve your options via get_theme_mod function.

You should take your time to read ALL of this:

And ALL of this:

I understand that that is a lot of information, but this is a highly competitive marketplace. If you are going to use outdated standards from the start, then your theme will be outdated sooner than you even finish it. You need to step up your game.

1 Like

Thanks for the help and awesome suggestions. I will keep in mind and definitely going to read even install them inside my brain then i will complete the remaining work. Thanks for all your answers @LSVRthemes. :heart:

@LSVRthemes Please look at this code. After reading you answer, i can guess that my theme standard will be rejected. But i have done making a lot of things for my theme and i want to make this theme bullet proof as you said. What can i do for this code:

div class="php  
if( !empty( $theme_options['opt-post-sidebar'] == true) ) { echo 'col-xl-9 col-md-9 col-sm-12 col-xs-12'; } else { echo 'col-xl-12 col-md-12 col-sm-12 col-xs-12'; } php'

Thats my original code, that i am using right now. Waiting for the reply. Thanks

With all due respect, but this is not a proper forum to learn the PHP / WP. If you are going to ask every single thing, the people will grow tired by your question and you won’t receive any answers at all.

Seek help in online forums specialized on PHP / WP programming. There are many private groups on FB as well. Register on StackOverflow, etc. Most importantly, learn to SEARCH for the information online. You are not reinventing the wheel. These are basic things you can easily find answers to online. You just need to put some effort into that. Without putting a lot of the effort you won’t make it as a professional anyway.

However, you can have the best code possible, the design is the most important part. You can always improve the code of the approved theme via updates. But you won’t be approved without a great design.

But to answer your question. I would do it like this (considering this code is inside some sort of template file and not in a function):

<?php if ( ! empty( $theme_options['opt-post-sidebar'] ) && true === $theme_options['opt-post-sidebar'] ) : ?>
<div class="col-xl-9 col-md-9 col-sm-12 col-xs-12">
<?php else : ?>
<div class="col-xl-12 col-md-12 col-sm-12 col-xs-12">
<?php endif; ?>

I would add to @LSVRthemes points - authors also need to be able to support, update, bug fix etc their items.

If it’s not your code, or at least that which you are familiar with and can work to build on where necessary, then you will be inviting bigger and ongoing issues in the near future once an item is approved.