Wordpress Multisite : Default page for newly created site - wordpress

I am new to wordpress multisite.
whenever I create a new sub-site and visit that sub-site it show 'Welcome to %s. This is your first post. Edit or delete it, then start blogging!'
My problem is I want to set a sample(Default)page for all the newly created sub-sit with custom text menu and theme instead of their default post.
is there any plugin that can help.
So my question is how to set sample(Default) page for each sub-site? instead of setting those page manually.
Any way to get rid of this issue?
Thanks!

By default, wordpress shows the latest posts page as front page when you create a new site
You can change that by going to Settings > Reading.
or you can use Refrence action:
function wporg_wpmu_new_blog_example( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
global $switched;
switch_to_blog($blog_id);
update_option('page_on_front', 'sample page id');
restore_current_blog();
}
add_action( 'wpmu_new_blog', 'wporg_wpmu_new_blog_example', 10, 6 );

Related

Wordpress remove permalink from custom posts but retain archive

I have a Wordpress site where I keep track of publications with an archive of custom post types called "publications". Each publication post shouldn't have its own page, it just needs to appear in the archive page. Right now when I create a publication called "test publication" there is a page created at www.mysite.com/publications/test-publication. I've seen the suggestion of changing the post option public to false, but then I can't access the archive itself, it just redirects to the home page. If I add publicly_queryable => true in addition to public => false then I can get to the archive page, but the dedicated page for each publication shows up again. I need it to give me a 404 if I try to visit www.mysite.com/publications/test-publication but still allow me to access the archive. Help, am I missing something obvious?
You can have template redirect added so that singular link if accessed redirects to Archive page:
add_action( 'template_redirect', 'disable_singular_publications' );
function disable_singular_publications()
{
if ( ! is_singular( 'publications' ) )
return;
wp_redirect( get_post_type_archive_link( 'publications' ), 301 );
exit;
}
You may add above function in functions.php , code is not tested so you may need to check on any typos or syntax errors.

How to remove wordpress date archive pages?

I have developed my own wordpress theme, and learning all kinds of programming stuff, but my priority is the content, not the programming knownledge. I need to know how to remove archive date listing from wordpress?
Question 1: The google search results displayed like this: virmodrosti.com/2017/05/
I don't want any kind of date archive option, how do you disable that?
I also don't use any kind of plugin, and always like to do it on my own.
Question 2: I don't know why older entries doesn't work anymore
virmodrosti.com/zdravje/ this page works fine
virmodrosti.com/zdravje/page/2/ it redirects to 404 error page
I only choose option in wordpress to hide that annoying /category/ with dash . inside editor at permanlinks, Category base. Maybe somehow these stuff is kinda fighting with each other and doesn't work properly.
Thank you.
This is code from Digital Nomad theme I maintain:
function digitalnomad_remove_date_archives() {
//if we are on date archive page
if ( is_date() ) {
// theme sets alternatine archive page with table like list of all posts
$archive_page = get_option( 'digitalnomad_archive_page' );
if ( $archive_page ) {
// redirs to alternatine archive page if configured (good for SEO)
wp_redirect( esc_url( get_page_link( $archive_page ) ) );
die();
} else {
// otherwise error 404 is displayed
global $wp_query;
$wp_query->set_404();
}
}
}
add_action( 'template_redirect', 'digitalnomad_remove_date_archives' );
Use the smart Archive Page Remover wordpress plugin
or visit your theme's functions.php file
then insert this code
/* Register template redirect action callback */
add_action('template_redirect','makes_remove_wp_archives');
/* Remove archive*/
function makes_remove_wp_archives(){
// if we are on category or tag or date or author archive
if(is_category()|| is_tag()||is_author()){
global $wp_query;
$wp_query->set_404();
}
}

How to create separate log-in and registration pages in WooCommerce

I want to seperate the login and registration page for woocommerce.
(there is a different solution that I don't get to work here:
Separate registration page in WooCommerce website)
I duplicated the form-login.php and renamed it to register.php
In the register.php template I deleted the login-content.
I want to add a page to wordpress and add the register.php template with a SHORTCODE to that page. How do I do this??
Then I could add a Register Link to the Login Page with
<?php _e( ' Register' ); ?>
and the new shortcode register page is loaded.
mmmhhh...
what do I have to add to the duplicated login /now register.php, that it can be loaded to any page with a SHORTCODE? that would be interesting.
Thanks for helping out!Best wishes, Mika
A more straightforward way to do this is to save the contents of the original form-login.php as form-login-single.php, and then replace the file form-login.php with:
<?php
if( isset($_GET['action']) == 'register' ) {
wc_get_template( 'myaccount/form-register.php' );
} else {
wc_get_template( 'myaccount/form-login-single.php' );
}
This way you don't need to modify your functions.php further, plus you don't run into any trouble with double-rendering of the register form that I got when using #Hassan-ALi's method.
You can create a copy of the Woocommerce form-login.php and name it form-register.php. The form-login.php is located in /woocommerce/templates/myaccount/ folder.
Then in the form-login.php you can create a link to the form-register.php using this code
register
// Separete Login form and registration form
add_action('woocommerce_before_customer_login_form','load_registration_form', 2);
function load_registration_form(){
if(isset($_GET['action'])=='register'){
woocommerce_get_template( 'myaccount/form-registration.php' );
}
}

Custom 'Edit Profile' Location in Wordpress

What I am trying to do is have the Edit Profile option in the Admin bar at the top of a wordpress page go to another url.
Basically instead of it going to the /wp-admin directory
I am trying to get it to go the the /editprofile.php page.
You can use the filter edit_profile_url:
add_filter( 'edit_profile_url', 'custom_profile_link_so_19216787', 10, 3 );
function custom_profile_link_so_19216787( $url, $user, $scheme )
{
return site_url( 'editprofile' );
}
I suppose that /editprofile.php is a page using this template and that its address is example.com/editprofile. If that's not the case, put a full URL instead of site_url($slug).
Related: Where to put my code: plugin or functions.php?

How to add page URL to list of pages in WordPress admin panel?

Currently, by default, the following columns appear in the list of pages in the WordPress admin panel:
Title
Author
Comments
Date
and because I have AIO SEO installed:
SEO Title
SEO Description
SEO Keywords
Is there a way to have WordPress also display the URL to the page (at least the part of the URL that is created when the page itself is created)?
The page url is actually already there by default, it's just hiding. When you hover over a page title, several links appear below the title -- edit, quick edit, trash, view. View is the hyperlink to the page, which you can click to view the page, or right click and copy the link address to use elsewhere.
Otherwise, if you are using a custom/child theme, you could add the following to your functions.php file:
add_filter('manage_page_posts_columns', 'my_custom_column', 10);
add_action('manage_page_posts_custom_column', 'add_my_custom_column', 10, 2);
function my_custom_column($defaults) {
$defaults['url'] = 'URL';
return $defaults;
}
function add_my_custom_column($column_name, $post_id) {
if ($column_name == 'url') {
echo get_permalink( $post_id );
}
}
Note: This just creates a text url to your page.
Also note, you do not want to edit your functions.php file directly if you are using a theme you did not create, as it will be overwritten when you update. If you want to add this to an existing theme, I'd suggest looking into child themes.
This is helpful. I would only improve the output slightly by removing the site url and just showing the page. Takes up less space and less to weed through visually.
if ($column_name == 'url') {
$siteURL=get_site_url($post_id);
$link= get_permalink( $post_id );
echo str_replace($siteURL,"",$link);
}

Resources