Overriding or Running a Script before Content of any Page

This topic contains 0 replies, has 1 voice, and was last updated by  Caezar De Castro II 11 months, 2 weeks ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #9461

    In this topic, we will discuss about code that can override any page or all pages. For a specific page, of course, you need to search for the specific slug that you want to override. But in general, for every page loaded including home, adding a filter to ‘pre_document_title’ gives you the opportunity to listen in each page. In the example below, we just want to edit the title of the tab.

     

    add_filter( 'pre_get_document_title', function( $wp_title ) {
        global $wp_query;
        $page_value = isset($wp_query->query_vars['category_name']) ? $wp_query->query_vars['category_name'] : true;
        if ($page_value == "jesus")
        {
            error_log('here');
            return "Custom Title!";
        }
        error_log('here');
        return $wp_title;
    }, 999, 1 );

     

    There are lots of uses for this tool, like for example, statistics plugin, maintenance plugin, and many more. But for now,  see Server Admin: Basic Manual for Performance and Security forum for more server administration and Easiest way of having a site is WordPress for other helpful tips and tutorials.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic. Login here