Custom page titles esc_url_raw($_SERVER['REQUEST_URI'])
-
Hey,
I’m using this hack for custom page titles:https://digwp.com/2010/04/custom-page-titles/
// Custom Page Titles add_action('admin_menu', 'custom_title'); add_action('save_post', 'save_custom_title'); add_action('wp_head','insert_custom_title'); function custom_title() { add_meta_box('custom_title', 'Change page title', 'custom_title_input_function', 'post', 'normal', 'high'); add_meta_box('custom_title', 'Change page title', 'custom_title_input_function', 'page', 'normal', 'high'); } function custom_title_input_function() { global $post; echo '<input type="hidden" name="custom_title_input_hidden" id="custom_title_input_hidden" value="'.wp_create_nonce('custom-title-nonce').'" />'; echo '<input type="text" name="custom_title_input" id="custom_title_input" style="width:100%;" value="'.get_post_meta($post->ID,'_custom_title',true).'" />'; } function save_custom_title($post_id) { if (!wp_verify_nonce($_POST['custom_title_input_hidden'], 'custom-title-nonce')) return $post_id; if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id; $customTitle = $_POST['custom_title_input']; update_post_meta($post_id, '_custom_title', $customTitle); } function insert_custom_title() { if (have_posts()) : the_post(); $customTitle = get_post_meta(get_the_ID(), '_custom_title', true); if ($customTitle) { echo "<title>$customTitle</title>"; } else { echo "<title>"; if (is_tag()) { single_tag_title("Tag Archive for ""); echo '" - '; } elseif (is_archive()) { wp_title(''); echo ' Archive - '; } elseif ((is_single()) || (is_page()) && (!(is_front_page())) ) { wp_title(''); echo ' - '; } if (is_home()) { bloginfo('name'); echo ' - '; bloginfo('description'); } else { bloginfo('name'); } if ($paged>1) { echo ' - page '. $paged; } echo "</title>"; } else : echo "<title>Page Not Found | Envision</title>"; endif; rewind_posts(); }
I have a custom mysql table with movie id and title and a “view-movie” page and I want to display the movie-title inside the <title>.
The esc_url_raw($_SERVER[‘REQUEST_URI’]) will return like: /view-movie/?id=70
I modified the code like this:echo "<title>"; $v_m_a = explode('/', esc_url_raw($_SERVER['REQUEST_URI'])); if (in_array("view-movie", $v_m_a)) { $id = $_GET["id"]; global $wpdb; $results = $wpdb->get_results("SELECT * FROM wp_mycustomtable WHERE id = $id"); foreach($results as $r) { echo $r->Titel; echo ' - '; } } elseif (is_tag()) { single_tag_title("Tag Archive for ""); echo '" - '; } elseif (is_archive()) { wp_title(''); echo ' Profil - '; } elseif ((is_single()) || (is_page()) && (!(is_front_page())) ) { wp_title(''); echo ' - '; } if (is_home()) { bloginfo('name'); echo ' - '; bloginfo('description'); } else { bloginfo('name'); } if ($paged>1) { echo ' - page '. $paged; } echo "</title>";
It is working fine. But is it save to use esc_url_raw($_SERVER[‘REQUEST_URI’]) or is there maybe a better way?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Custom page titles esc_url_raw($_SERVER['REQUEST_URI'])’ is closed to new replies.