0

I'm creating a custom php/js pages querying and displaying results from a separate non-wordpress DB on a 2nd page. The header and footer will be the same as my theme so I'm calling the theme's footer and header but I haven't figured out why my hook to customize the pages' title aren't working and am asking which hook to use to display my designated title.

I don't need to call any content from wordpress besides the theme's header and footer (1 reason why I'm not using a page template).

I thought to do

require('../wp-blog-header.php');
get_header();
add_filter( 'wp_title', 'mycustom_title', 4);

function mycustom_title($teetitle) {
    $teetitle = 'My Custom Title Here';
    return $teetitle;
}

as described here and (my full php file is here)

I'm able to call the header using 'get_header' and my header.php file in my theme calls wp_head.

At this point, I'm stumped because my hook to wp_title is not firing and is following the default logic of stating 'page not found' for a 404 in general-template.php

I thought I could override by issuing a hook immediately after calling get_header in my php file ; https://stackoverflow.com/questions/9926292/set-custom-page-title-with-hook but this is not working.

When I issue $echo wp_title in the body later in the same file, wp_title gives me my modified title.

I've also tried a couple default different themes (2013, 2012, etc) and the page title is not correct so I think there's something fundamental that I'm missing or that I'm not calling the correct hook. I've also tried placing my hook in my theme's function.php and had the same result. I've also tried using a priority of a 6 digit integer, and still had same result.

  • Don't ever require core WordPress files in your custom PHP scripts. You can always use an API, such as REST. – Jack Johansson Aug 22 '17 at 19:33
  • 1
    It is not possible to get header and footer via API. So the best way is to create page template by your functions.php or mu-plugin. – Anton Lukin Aug 22 '17 at 20:03
0

I ended up making a page template anyways and inserting the page title when making the post.

-1

It doesn't work this way. You should load all wordpress environment, than with template_include or template_redirect hooks use your own template with header.

For example:

<?php
    require('../wp-blog-header.php');

    add_action('template_include', function() {
        if($some_condition === true) {
            $new_template = locate_template( array( 'portfolio-page-template.php' ) );

            return $new_template;
        }
    });

    add_filter('wp_title', function($title) {
        return "new title";
    })

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.