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.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #225518

    Master
    Participant

    In 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

    #225530

    Artem Temos
    Keymaster

    Hi,

    Could you please send us a link to your website where we can see this issue?

    Kind Regards

    #225543

    Master
    Participant

    The 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>’ );
    }
    }
    }

    #225586

    Artem Temos
    Keymaster

    Sorry, 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.

    #225596

    Master
    Participant

    Please 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.

    #225640

    Artem Temos
    Keymaster

    We 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.

    #225697

    Master
    Participant

    The 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?

    #225765

    Artem Temos
    Keymaster

    Before uninstalling the theme you have to deactivate the license to avoid activation problems in the future.

    #225832

    Master
    Participant

    Can 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

    #225925

    Artem Temos
    Keymaster

    You can deactivate the theme license in Dashboard -> WoodMart -> Theme license.

Viewing 10 posts - 1 through 10 (of 10 total)