CMS Development Wordpress

Setting the page title in a plugin, but not outside my plugin

I am writing my first humble plugin, which gets items from a simple database. For good SEO, I want to set the HTML title to be the item name, varying according to my users choice.

My user enters some choices on a form and I show results. Each item has one page and the URL gives me ?item=12345 so I can get the item name from my database. All this works.

I can successfully set the title, by setting up this in my top (“bootstrap”?) file of my plugin:

add_filter( 'pre_get_document_title', 'dwnz_filter_pagetitle', 20 );

to call my function (which queries the database for the item name).

My problem is: this filter is being invoked through the whole website, not just when my plugin is being used. How do I limit this call just to my plugin pages?

Leave a Reply

Your email address will not be published. Required fields are marked *