How do I create a new page from my Wordpress plugin - wordpress

In my wordpress plugin, I want 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();
?>

Related

WordPress: Hide all the pages and posts expect for some pages

I have a multisite installation and I'm using one site for my landing pages. I want to hide all the pages on that site expect the landing pages that you need to have the URL to access.
I searched for a plugin that could do that but didn't find one. Is there anything that we can do with .htaccess? I tried looking into this but just looking at .htaccess gives me a headache and I don't want to break something for the other sites as this is MS installation.
Any help would be appreciated.
You can redirect from sites u don't want to be visible into other sites. In order to do this u can use this plugin:
https://pl.wordpress.org/plugins/redirection/
or if u know some php u can use hook and redirect.
Write and adjust in functions.php code below:
function wolfie_redirect_sample() {
if(is_front_page()) { //in this place u can use any other conditional
exit( wp_redirect( site_url( '/this_is_ur_landing' ) ) );
}
}
add_action( 'template_redirect', 'wolfie_redirect_sample' );

My wordpress comment reply not working, please i need a solution

I formerly used a Wordpress theme where users could make comments on items I posted and also could make replies on comments made by other users on my Wordpress site.
I later changed my theme on Wordpress and I used a callback in my comment list in comment.php like this:
Then I coded the comment list form in my functions.php, and later noticed that when a user clicked the "reply" button below a comment, the page only reloaded but the comment reply is not working.
Please I really need help to resolve this. This is how I coded my "reply" form in my functions.php: $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
Please is there any way I can resolve this? I will appreciate a reply... Thanks
Check if comment-reply.js is loaded on the page.
EDIT:
This should be already included in your theme's template files that handles the comment feature. View the page source to see if its included, if its not included then to include the this file. Goto functions.php and add this code.
<?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?>

Seo yoast plugin, breadcrumbs

This is question on the seo yoast wordporess plugin.
I have a friend who doesn't know that much about code/wordpress/etc, they have an ecommerce site built using magento and a blog using wordpress which is styled to match the main site and they use yoast seo plugin for seo etc. They have asked me to try an get the breadcrumbs working for them in a different way to what i know, from what i can see they want to add a prefix to the breadcrumbs 'home' which links to main site then renaming the blog from home to blog, for example home(main site) > blog(blog) > post.
Now i did just that in the plugin settings but they said that the schema markup wouldn't be complete and said there’s a filter hook called ‘wpseo_breadcrumb_links’ which gives access to the array of URLs and anchor text used to build the breadcrumbs, now i cant find anything on google that explains this or how to start writing it, i do know that it needs to go in the functions file.
Would it be possible to get some help on this.
Thanks in advance and very much appreciated.
Justin
I'm not sure what Schema.org markup has to do with breadcrumbs! :) Schema is used on post/page level. So, they are either oversmarting themselves or I got you wrong.
I think this sample code may be helpful:
add_filter( 'wpseo_breadcrumb_output', 'custom_wpseo_breadcrumb_output' );
function custom_wpseo_breadcrumb_output( $output ){
if( is_product() ){
$from = '<span typeof="v:Breadcrumb">Products</span> »';
$to = '';
$output = str_replace( $from, $to, $output );
}
return $output;
}
It looks like wpseo_breadcrumb_output gives you access to the entire output instead of just the link portion. Please see this page for more details: http://wpquestions.com/question/showChrono/id/8603

pagination fails when including custom variable in permalinks in wordpress

I'm a wordpress newbie here so please go easy on me.
I am working on a wordpress site and I've run into two problems I just can't seem to find the answer to anywhere. I have permalinks set up on my wordpress site, along with paging, so for example, www.mysite.com/links/page/2 sends you to the second page of links.
I just created a custom template that pulls in two different taxonomies with the same tag name. To do that I created a page called tags that uses my custom template and I have a custom link that goes to it with a structure of: www.mysite.com/tags/?tag=mytag This is ugly but it works for testing purposes.
The problem happens when I go to page two and the link is: www.mysite.com/tags/?tag=mytag/page/2 which doesn't work.
I don't want to mess up my current permalinks, but I want to add a new rule that a) stops the page from breaking, and b) actually looks good. I would like to have the link just be www.mysite.com/tags/mytag/page/2
After a ton of digging I was able to get what I thought was the right code. This is what I've added to my functions.php in my theme directory:
add_action( 'generate_rewrite_rules', 'my_tag_rewrite_rules' );
//add_filter( 'query_vars', 'my_tag_query_vars' );
function my_tag_query_vars( $vars )
{
// $vars[] = 'tag'; // might not need this because 'tag' should already be registered
}
function my_tag_rewrite_rules( $wp_rewrite )
{
$wp_rewrite->rules = array(
'tags/([^/]+)/page/?([0-9]{1,})/?$' => $wp_rewrite->index . 'tags/?tag=' . $wp_rewrite->preg_index( 1 ) . '&paged=' . $wp_rewrite->preg_index( 2 ),
'tags/([^/]+)/?$' => $wp_rewrite->index . 'tags/?tag=' . $wp_rewrite->preg_index( 1 )
) + $wp_rewrite->rules;
}
(I commented out the add_filter part because 'tag' was already a query variable wordpress recognized). From what I read it looked like all I needed to do was go into the wordpress dashboard and go to settings->permalinks and supposedly it would change the .htaccess. It didn't.
My first question, is: is my rewrite rule correct? and secondly, what else do I need to do to get wordpress to update the .htaccess file?
Thanks a ton for any help!

custom taxonomy terms page not found Wordpress

I’m getting a Page Not Found message when clicking on the link to display the terms in a taxonomy
Scenario:
I have a custom post type called "glossary"
Attached is a custom taxonomy called "section" with the rewrite set to “library/glossary-start-here”
I created a page that lists the terms in the taxonomy. This is a Wordpress page with the slug of “glossary-sections” - the template for the page is set to “taxonomy-section.php”. The page is a child of “library” and so the permalink for the page is “example.com/library/glossary-starts-here/glossary-sections/"
The template “taxonomy-section.php” has the following code:
<?php // Begin header section.
$argterms=array(
'include' =>array(
117,118,115)
);
$terms = get_terms('section', $argterms);
echo '<ul>';
foreach ($terms as $term) {
echo '<h3>' . $term->name . '</h3>';
}
echo '</ul>'; ?>
<div>
<?php
When clicking on the link to the page “glossary-sections”, which is used on a number of other pages, I get a page not found message.
I know the template does its job because on some occasions as I've poked around troubleshooting I've had it working. However, I can't find a consistent condition that causes the page to work. I suspect that the problem has something to do with the rewrite but my tests have been inconclusive.
I’d appreciate any suggestions on why this isn’t working and how to correct it.
I’m particularly puzzled by the fact that I can specify a page like “glossary-section” and yet have it not be found.
Thanks.
As I understand it, WordPress has a hierarchy / parse order (so to speak) as to what it looks for when it gets a request. Technically, a taxonomy is just a tag.
I'm not sure if this will help:
http://justintadlock.com/archives/2009/06/04/using-custom-taxonomies-to-create-a-movie-database
But J.Tadlock is always a solid place to start.
The source of the problem was that I had included a rewrite for the taxonomy, while at the same time using pages with assigned templates.
Once the rewrite was removed it appears that everything worked correctly.

Resources