get title of current page
-
I am writing a plugin that records the page title when a page or post is viewed.
It appears the loop runs for each sub-page of a page (e.g. blog page) and I’m getting multiple titles. (If there are three sub-pages, I get three titles).
How do I get only the title of the page that is displayed to the site visitor? If they view the second sub-page, I want that title only, etc. — i.e. I want what is inside the HTML header <title>page name</title> tags.
I’ve tried different hooks into the loop and different code to retrieve the page title. I now think I need to do this
- outside
the loop but don’t know how
Relevant portion of my code:
<?php //add_action('init', 'wlog'); //add_action('wp_head', 'wlog'); add_action('wp', 'wlog'); //add_action('wp_footer', 'wlog'); $page_name = wp_title('', false);
Any help would be appreciated.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘get title of current page’ is closed to new replies.