Tom
Tom

Reputation: 936

Wordpress plugin URL rewrite

I have a wordpress plugin which enables me to add events to my website.

However the url structure is e.g.

domain.com/events/cat/event-name

I was looking into the plugin, however I was not able to locate the way how the plugin reacts to that request.

Thus comes my questions:

What different ways are there for a plugin to be called via a certain url structure (like above e.g. all urls which contain "/events/cat" belong to the plugin) ?

I was looking at my .htaccess file but it was unchanged, also i was looking if the plugin uses a

add_action('parse_request', 'handler_action');

But I couldnt find anything. Are there any other ways the plugin could be using?

Thanks a lot!

Upvotes: 1

Views: 2672

Answers (1)

silver
silver

Reputation: 5311

Its probably using a custom post type using register_post_type function, this will then build a new URL rewrite rule

The other possible method is by using add_rewrite_rule

something like

add_action('init', 'your_plugin_rules');
function your_plugin_rules() {
    add_rewrite_rule( "events/cat/(.+)/?$", 'index.php?events=$matches[1]', "top");
}

if you check and print the value of $wp_rewrite you can see all the rewrite rules

e.g.

add_action('wp_head', function() {
    global $wp_rewrite;
    echo '</pre>', print_r( $wp_rewrite, 1 ), '</pre>';
});

Upvotes: 1

Related Questions