?author=0 keeps accessible (wordpress). What is this template? - wordpress

I can't get http://www.mywebsite.com/?author=0 unaccessible. I'm aware of different type of standard templates WordPress provides us with. So I use the following code:
add_action('template_redirect', 'page_template_redirect');
function page_template_redirect(){
global $wp_query, $post;
if (is_archive()){
wp_redirect(get_option('home'));
exit;
}
}
This should redirect all author archives, category pages, taxonomy pages etc. to my home. I'm not building a blog so I don't want these pages to show up in Google. I'm also building a template which should be re-usable, so I want everything to work on template-level. Best is no manual htaccess edits.
It blocks all my author pages like /author/ and /?author=1, but it doesn't block the /?author=0 page. It shows a list with all my posts from my index.php (which I'm not using since I'm using a custom homepage template). is_author() or is_archive() result in 'false'.
Where does this page come from and how can I prevent that it shows up in Google? I would like to configure it from my theme to redirect or 404.

Related

Wordpress: redirect all posts (projects) to certain page

I'm trying to redirect all posts (in my theme called projects) to a certain page (also the homepage). I'm using those projects (title, thumbnail and description) only to feed into a thumbnail grid on the homepage – now they are still found by search engines and then lead to blank page.
I've tried multiple redirect plugins and with those, it seems like I need to add every single project individually (or via bulk) but this is especially annoying when new ones are created.
Hence I'm looking for a "general rule" to simply redirect all posts (projects) to the page "home".
You should be able to add a simple redirect to the functions.php file:
add_action('template_redirect', 'proj_redirect_to_home');
function proj_redirect_to_home()
{
global $post;
if (is_single() && $post->post_type=='post')
{
wp_redirect(esc_url(home_url('/')));
exit();
}
}

Using Jetpack Portfolio Project in WordPress child theme does not call archive custom template

I have a child theme that uses the new Jetpack Portfolio Project custom post type and wish to modify archive.php to display custom results.
I'm using: WordPress v3.9.2; Theme: Child of Point, Jetpack is installed with Custom Content Types enabled, and Portfolio Projects selected in the Settings. (No other plugins that implement portfolio functionality are installed.)
According to the Codex:
Template Files
In the same way single posts and their archives can be displayed using
the single.php and archive.php template files, respectively,
single posts of a custom post type will use single-{post_type}.php
and their archives will use archive-{post_type}.php
and if you don't have this post type archive page you can pass BLOG_URL?post_type={post_type}
where {post_type} is the $post_type argument of the
register_post_type() function.
My understanding is that if you create files called single-jetpack-portfolio.php and archive-jetpack-portfolio.php within the child theme, WordPress will automatically use those files in place of single.php and archive.php respectively.
However, my child theme successfully calls single-jetpack-portfolio.php, but completely ignores archive-jetpack-portfolio.php, instead calling archive.php in the child.
I am stuck for a solution.
From the codex above, adding to the URL "?post_type=jetpack-portfolio" does cause the child theme to correctly use archive-jetpack-portfolio.php, but should I need to be manually modifying every single URL to explicitly specify this? Should WordPress not automatically be detecting this, as it does for the single-jetpack-portfolio.php file? How can I solve this?
I have tried:
Resetting the permalinks in case it was related to that (changing the option in Settings and saving and back again)
Adding an archive.php file to the child in addition to archive-jetpack-portfolio.php (I initially didn't have an archive.php in the child, so it used the parent's archive.php)
Publishing a new Jetpack portfolio project and updating an existing page (I read somewhere that publishing something might trigger Wordpress to see the changes)
Thanks in advance for any help.
I had the same problem described by the OP. When I visited mydomain.com/portfolio it would use the custom archive template. When I tried to view a project type it defaulted to the regular archive.php. I'm wondering if OP was viewing a project type page without realizing it.
My solution was to create a taxonomy template file. After playing around with it I figured out that
taxonomy.php
taxonomy-jetpack-portfolio-type.php
taxonomy-jetpack-portfolio-type-{name-of-project-type}.php
all worked correctly, depending on how specific you wanted to get.
There's more info at the wordpress codex: http://codex.wordpress.org/Template_Hierarchy#Custom_Taxonomies_display
Hope this helps someone.
I will be working on this the next days.
You should try this in the child archive.php first lines:
<?php
if( is_post_type_archive('jetpack-portfolio') )
get_template_part('content', 'jetpack-portfolio');
elseif( is_tax('jetpack-portfolio-type') || is_tax('jetpack-portfolio-tag') )
get_template_part('archive', 'jetpack-portfolio');
else continue;
?>

Custom Plugin for wordpress with hierarchy of SEF pages

Here's my issue. My company needs a vendor database added to our wordpress website. None of the existing plugins will even come close to what we need, and we already have a mysql database with all of our information, so we need to create a plugin or something to do what we need.
These urls need to be direct-accessible and have SEF urls. So, for example:
mysite.com/vendors/
mysite.com/vendors/pipe-manufacturers/
mysite.com/vendor/bobs-pipes/
And, the custom content needs to appear inside the wordpress template.
There are really 2 options:
1) Find a way to write our application outside of wordpress, but find a way to bootstrap wordpress to show the header, footer, and sidebar.
2) Run the app from inside wordpress.
So I went for option #2. I created a new template file named "vendor.php", and began working. I added this code to my functions.php of my theme:
add_filter( 'template_include', 'xyz_template_check' );
function xyz_template_check() {
global $template;
$rqst = $_SERVER['REQUEST_URI'];
$ra = split("/", $rqst);
if ($ra[1] == "vendors") {
$template_file = get_stylesheet_directory() . '/vendors.php';
return $template_file;
}
return $template;
}
So what the above code does, if it sees the word "vendors" as the first part of the url after the site name, it sends you to vendor.php. This works PERFECTLY....
except...
Wordpress believes that the page is not found. It returns a 404 header, and NOT FOUND into the page title and breadcrumb.
Adding a PAGE called "Vendor Database" with the permalink "/vendors/" fixes the main page. But there will be literally hundreds of vendors and different categories. I cant be creating a custom page for each one. This needs to be dynamic.
So, how do I make wordpress give a 200, and supply an acceptable page title, breadcrumb, etc.
Don't even get me started on the danged wp_title filter. This did NOT work as documented. Although, it just occurred to me that this might be an issue with Wordpress SEO (the wp_title filter issue).
Anyone got an idea on this?
Ok got this. The solution was to use the rewrite api, as mentioned above, to look for the pattern /vendors/, letting it know that it was a valid URL. Coupled with my existing template override, this is what I needed.

Rewrite category wordpress

Is it possible to rewrite only one category ?
I have a category "Photos" and just for this category.
I just want to rewrite it from /category/photos to /photos
You can do it with WP Rewrite API.
Add this to functions.php
add_action('init', 'register_rewrites');
function register_rewrites() {
add_rewrite_rule('^photos$', 'index.php?category_name=photos','top');
}
Remember to reload your rewrite settings: go to Settings -> Permalinks and click on Save button - no changes needed.
The Yoast SEO plugin has this function build in, I recommend this plugin in general.
no-category-base-wpml only does this
If you don't want to install a plugin for this. Around the web there are many tutorials which do this:
http://thisismyurl.com/6704/remove-category-url-wordpress/
http://www.webdevtuts.net/php/how-to-remove-category-from-wordpress-url-structure/
http://www.wprecipes.com/how-to-remove-category-from-your-wordpress-url
Too enable this for just one category I would advise the following:
create a page called photos.
create a theme template page for this photo page
In is set up a new query_posts* getting the category 'photos'
Include the category.php file.
assign that template to the photo page.
Not tested but should work. Because the page has the correct URL and should include the category. Questions, aks.
*query_posts is bad for performance if you want to do it totally correct use the pre_get_posts filter. It's requires more knowledge.

How do I create a custom WordPress page?

I want my WordPress blog to have a page called music. On that page I will query the DB for posts with the category music and then change around the look and feel of the posts. So I can't just put a link to /categories/music/ because I want to do custom work on the posts.
Should I put this code in a separate php file and link to it? I think I may lose access to all the nice WordPress API calls if I do that.
I was thinking about using a filter, but I am not sure which one to use. I was thinking something like the following except the_title has not been grabbed yet so I cannot check the title.
function show_music(){
if( is_page() && the_title('','',false) == 'music' ){
echo "got here";
}
}
add_filter('pre_get_posts', 'show_portfolio');
How would you go about this?
You need to put the below code in the file, and then put the file in the Theme folder. Then you can create a page using Wordpress pages and select a page template with the name you put in this comment:
/*
Template Name: Something Goes Here
*/
You need to create custom page within your theme. If you dont have idea how to create custme page or template page in WordPress theme then view my easy tutorial How to create template page in WordPress

Resources