276 reputation
112
bio website r-interface.blogspot.com
location Chisinau, Moldova
age
visits member for 2 years, 7 months
seen 17 mins ago

16m
comment How to assign a class to a page with a custom template?
Yes. Thank you very much!
16m
accepted How to assign a class to a page with a custom template?
3h
revised How to assign a class to a page with a custom template?
improved the answer
4h
comment How to assign a class to a page with a custom template?
@MayeenulIslam I edited your answer, please accept.
4h
suggested approved edit on How to assign a class to a page with a custom template?
4h
comment How to assign a class to a page with a custom template?
@MayeenulIslam The whole problem arose because of the wrong structure of my template, which I just adapted from the parent theme (missed the name of template: Template Name: My Template). Now the problem is solved and I can assign an additional body class with the first code snippet from my question. Your code will also work if you will remove the return from the conditional if. Now it produces two warnings: Warning: array_unique() expects parameter 1 to be array, string given in /var/www/.../public_html/wp-includes/post-template.php on line 721. Warning: join(): Invalid arguments ...
5h
comment How to assign a class to a page with a custom template?
:) hahaha, but it is so, or I don't understand something. I have only a page-template-default class.
5h
revised How to assign a class to a page with a custom template?
updated the question
5h
comment How to assign a class to a page with a custom template?
No success :(. Maybe because of my theme? And my page with a custom theme don't have these two classes. BTW, I assign the template to this page with a function (I will update the question). I cannot do that from the admin dashboard, because I don't have this option. Maybe this function is wrong?
5h
revised How to assign a class to a page with a custom template?
updated the question
5h
comment How to assign a class to a page with a custom template?
@MayeenulIslam The template is located in the child theme main folder.
5h
comment How to assign a class to a page with a custom template?
@mmm @PieterGoosen I replaced get_page_template_slug(get_the_ID()) === 'mytemplate.php' with is_page( 8 ) (8 is the ID of the page) and now the function works. But how to use the template slug?
6h
comment How to assign a class to a page with a custom template?
Not in my case. @PieterGoosen, this is the output: array(6) { [0]=> string(4) "page" [1]=> string(9) "page-id-8" [2]=> string(21) "page-template-default" [3]=> string(9) "logged-in" [4]=> string(9) "admin-bar" [5]=> string(20) "no-customize-support" } class="page page-id-8 page-template-default logged-in admin-bar no-customize-support">.
6h
comment How to assign a class to a page with a custom template?
I added a row to the function: echo get_page_template_slug(get_the_ID());, but I don't see an output.
6h
asked How to assign a class to a page with a custom template?
7h
comment Add parent template name to body class filter when visiting subpage or single post
@Bainternet I got an error with your code: Fatal error: Cannot use object of type WP_Post as array in /var/www/.../public_html/wp-content/themes/birdtips-child/functions.php on line 285. The mentioned line is $classes[] = $post[0]->post_slug;. Can this be repaired? I added the rewind_posts(); before return $classes; as you suggested but this didn't helped.
7h
comment Change template dynamically
@Milo Is there any way to add a class to the template with your first code snippet?
1d
comment Adding a jQuery rotator function
Not me, this was @kaiser :).
1d
comment Use AJAX in shortcode
@toscho When I enabled the define('WP_DEBUG', true); in my wp-config.php this solution generated an error: Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method Ajax_Shortcode_Demo::get_instance() should not be called statically in /var/www/.../public_html/wp-includes/plugin.php on line 496. Is this critical? I changed it a little: wordpress.stackexchange.com/q/196332/25187
1d
asked Adding a jQuery rotator function