Hi Guys,
There are times when you write a plugin that has to create a page and the page contents would be a shortcode handled by your plugin.
Now when thats the case your landing page title will always be the same.
Question is how we can change it depending on your post or page ID.
This post will just give you an Idea but the final pen up has to be done by you.
Look at the function below that defines a filter function that you will modify and add it to your plugin file
1 2 3 4 5 6 7 8 9 10 11 12 13 |
function plugin_chgtitle_example($title){ global $wpdb; // global wordpress database object $append_title = ""; // In this example I am taking my stored page ID from the wordpress options and comparing it with the current post ID being viewed by user if(intval(get_option("plugin_page_id")) == get_the_ID()) { $id = intval($_GET["id"]); if(intval($id) > 0) { $row = $wpdb->get_row($wpdb->prepare("select * from YOUR_TABLE where id=%d",intval($id))); $append_title = $row->title; } } return $title." ".$append_title; } |
Few assumptions in the above code but as a plugin dev you will understand what those are
Now In you main plugin file just add filter to handle filter hook called wp_title as shown below
1 |
add_filter('wp_title', 'plugin_chgtitle_example', 100); |
That pretty must it. Now if you are in doubt please use comments to ask questions so that others including myself can reply.
I hope this helps
Cheers,
Advertisement
Leave a Reply