开发者

How do I create a new page from my Wordpress plugin

In my wordpress plugin, I w开发者_高级运维ant to generate a page on the fly.

I could have the user create the page for me. But I would rather not have them do any steps. Just let them activate it and it works.

So I was wondering is there a way for me to do this, which maintains all the functionality within the plugin.

My initial idea was to add a rewrite rule

add_rewrite_rule('my_page/$', 'wp-content/plugins/my_plugin/page.php', 'top');

Then in my plugin I can have a page.php. Which works well, but I cannot get the header/footer etc.

I am very new to wordpress, so chances are i am missing somethign obvious.


You could create a 404 page code snippet that does wp_insert_post() and then redirects the user to it.

Your theme's 404.php would look like this:

<?php
$post_id = wp_insert_post("post_title" => "my post title", "post_content" => "Lol");
header("location:" . get_permalink( $post_id ) );
die();
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜