Manually register template

Home Page – v1.1 Forums Extensions Layout Manager Manually register template

This topic contains 2 replies, has 2 voices, and was last updated by  Mark Woodroof 4 years, 1 month ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #4861

    Mark Woodroof
    Participant

    Hi

    I am trying to use Layout Manager to manually register a template and have created the slug and template page and put the recommended code in my functions.php as per your example:

    function register_my_contexts () { 
    $news_template = locate_template('category-news.php'); // returns full path of file in theme folder
    register_context( 'News Category', 'category_news', $news_template); }// $name, $context, $template_file

    However, it does not seem to be working…I am not sure what I am doing wrong?

    I am using the Bootstrap Starter as my base theme.

    Any tips?

    Thanks

    Mark

    #4868

    Andy Wilkerson
    Keymaster

    The code above looks similar to the example code we show. Is the template file you are registering for a category and does a ‘news’ category exist in your theme? WordPress recognizes custom templates for categories. You can create those with the naming structure category-{slug}.php so we picked that as or example.

    What is the template file you created?

    I think the problem is probably because the entire registration function is being wrapped inside another function that’s never called. Are you calling the register_my_contexts() function anywhere?

    You could try this:

    function register_my_contexts() { 
        $news_template = locate_template('category-news.php'); // returns full path of file in theme folder
        register_context( 'News Category', 'category_news', $news_template); // $name, $context, $template_file
    }
    // Apply filters
    add_action( 'wp_loaded', 'register_my_contexts' );
    

    If you’re never calling the function it’s not going to work. The above code uses the ‘wp_loaded’ action to call the function after WP if fully loaded. That’s not required but it’s a nice place to use it to ensure all the template files and functions have been registered by the system first.

    #4872

    Mark Woodroof
    Participant

    Hi Andy

    Yes – this is the exact example code you provided. I could not see the wood for the trees and (schoolboy error!) was not calling the function correctly.

    Thanks for your help.

    Mark

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

You must be logged in to reply to this topic.

Fork us on Github.

Runway on Github

Learn with User Guides.

View the Guides


Thank you for being a part of Runway. We hope you have a great experience and together we can make Runway one of the best additions to the WordPress ecosystem and theme development. We're excited to have you here!

escort kutahya escort bornova escort beylikduzu escort amasya escort diyarbakir
Google+ ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?> ?>