Home › Forums › WoodMart support forum › add_action( 'init', 'my_function_name' ) – Missing header and footer.
add_action( 'init', 'my_function_name' ) – Missing header and footer.
- This topic has 9 replies, 2 voices, and was last updated 4 years, 5 months ago by
Artem Temos.
-
AuthorPosts
-
September 11, 2020 at 12:33 pm #225518
MasterParticipantIn my child function file I intersect the wp-admin url if a user is not administrator. The problem is:
` global $wp_query;
$wp_query->set_404();
status_header( 404 );
nocache_headers();
get_template_part( ‘404’ );
exit;This code is hooked on add_action( ‘init’, ‘my_function_name’ );
Everything works as expected, the template part displays the 404 page but the header and footer are missing. I checked the source, the header tag and footer tags are present but the content inside of them is missing.
Can you please check this out and let me know what I am missing? Thanks
September 11, 2020 at 1:07 pm #225530
Artem TemosKeymasterHi,
Could you please send us a link to your website where we can see this issue?
Kind Regards
September 11, 2020 at 2:36 pm #225543
MasterParticipantThe website is live but under maintenance mode and all the code that has to be uploaded is on localhost still.
Please paste this code to your child functions.php file and go to wp-admin, it will only take you a minute to see the problem.
`/**
* Xthemos test code.
*/
if ( ! function_exists( ‘xthemos_test_code’ ) ) {
add_action( ‘init’, ‘xthemos_test_code’, 1 );function xthemos_test_code() {
if ( is_admin() ) {
global $wp_query;
$wp_query->set_404();
status_header( 404 );
nocache_headers();
get_template_part( 404 );
exit( ‘<div style=”color:red;font-weight:bold”>THIS CODE DISPLAYS THE 404 TEMPLATE BUT MISSING THE HEADER AND FOOTER! VIEW SOURCE CODE.</div>’ );
}
}
}September 11, 2020 at 7:10 pm #225586
Artem TemosKeymasterSorry, but additional code customizations like this are out of our theme support scope. We are not responsible for any third-party code that is not related to our theme.
September 11, 2020 at 7:32 pm #225596
MasterParticipantPlease don’t get rid of me like that, I just need a simple code snippet from your developers so I can display 404 error page with the header and footer, currently is displaying the 404 template but the contents of the header and footer are missing.
So I am calling the get_template_part( 404 ) on init hook, the template displays but header and footer are missing, this is simple wordpress code that usually works in all themes but with this theme it does not work and I just want to know do I have to include some file from the parent theme or change the code.
I don’t have the time to search through the entire code of the parent theme to find why the header and footer contents are missing, I know that both are dynamic and are called in a different way, I just need to include them with the 404 template.
Thank you.
September 12, 2020 at 7:15 am #225640
Artem TemosKeymasterWe don’t know why this code is not working for you.
We suggest you to create a page like 404 and set the redirect function to that custom page. That should work correctly.
September 12, 2020 at 12:34 pm #225697
MasterParticipantThe code is working like it should but the get_template_part() is not since it’s hooked on init action that is run before tamplate.
I got it working at the end.
One more question.
I will be reinstalling the entire database and wordpress with all its plugins, will I have any problem when entering again my purchase code on live server?
September 13, 2020 at 6:09 am #225765
Artem TemosKeymasterBefore uninstalling the theme you have to deactivate the license to avoid activation problems in the future.
September 13, 2020 at 1:17 pm #225832
MasterParticipantCan you explain a bit in detail how should I do it? (the licence deactivation/reactivation)
Here are the actions:
– I will drop the database.
– I will upload wordpress core with all the plugins and theme.
– Reinstalling wordpress.Thanks
September 14, 2020 at 6:11 am #225925
Artem TemosKeymasterYou can deactivate the theme license in Dashboard -> WoodMart -> Theme license.
-
AuthorPosts
- You must be logged in to create new topics. Login / Register