Change a homepage based on theme wordpress - wordpress

I have 2 themes in my WP installation: Theme, Theme2, and separately I have 2 Homepages, one for each theme.
Is it any way for me to change a homepage based on active theme dynamically?
So, Example if i'll activate Theme2, Homepage2 becomes a main homepage?
Ideally, i want something like:
if ( current_user_can( 'manage_options' ) ) {
switch_theme('twentytwelve');
/* Activate Homepage_1 */
} else {
switch_theme('twentythirteen');
/* Activate Homepage_2 */
}
}

Change a homepage based on theme wordpress
You can follow this steps and set the homepage page as you have activated the theme.
Click on “Pages” from your dashboard.
Click the “Add New” button on the top and create a new page called, “Homepage.”
Go to “Settings” from the dashboard, and click on “Reading.”
The first option available is called “Front Page Displays.” Change it to “A static page.”
In the “Front Page” drop down, you should see your new homepage. Select it and save your changes.
Go back into “Pages” and click on your homepage.
Add the shortcodes you want to display.
Update your homepage.

Related

Add orderby="rand" function in wpbakery Wordpress

I have a theme for an eCommerce website and my homepage is built with wpbakery. Products displayed in the homepage are not changing after refresh. All the products are in the same place. I found no option in wpbakery elements to change order by random. How can I add this functionality?
I am sure in wpbakery there is a way you can do this by selecting a random option. But if you are unable to find it check and see if this works in your case.
add_action('pre_get_posts', 'my_pre_get_posts');
function my_pre_get_posts($query) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set('orderby', 'rand');
}
}
Put the code in your function file. It will set your homepage post orderby rand. Hope it works but I advise you to follow WPbakery setting to do that.
Simple Steps to find your way in WPbakery
make sure your plugin is active
Go to the page set as your homepage and click on edit page
open the post setting in the wpbakery
Select Data setting
Choose the first option which is "Order by"
scroll down and select "Random order" and save your setting.
That should point you to the right way to set random post order in WPbakery.

Removing certain links in admin header bar added by plugins

I have instaled several plugins and they tend to add links on the admin bar that is
I have ultimate affiliate pro and it has added new and referral affiliate and other plugins like ithemes security has a link on the admin bar such that now my admin bar looks mesed up like in the image below
How can i edit this is there a plugin which can remove certain links on the admin dashboard bar without having to disable the plugins
I have tried:
checking on the screen options but there is no way to uncheck links
Here is the example of how you can remove the unwanted links from admin_bar.
function remove_admin_bar_links() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('wporg'); // Remove the WordPress.org link
$wp_admin_bar->remove_menu('documentation'); // Remove the WordPress documentation link
$wp_admin_bar->remove_menu('support-forums'); // Remove the support forums link
$wp_admin_bar->remove_menu('feedback'); // Remove the feedback link
$wp_admin_bar->remove_menu('w3tc'); // If you use w3 total cache remove the performance link
$wp_admin_bar->remove_menu('my-account'); // Remove the user details tab
}
add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' );
You need to check the menu name and add it to the function call via add_action.

How to stop showing menu in static home page wordpress

Ok, I'm creating a wordpress theme. I don't want my navigation menu to show in the home page "Only" if the site admin setup Front page displays > A static page (select below).
otherwise I want to show the menu in home page & other pages too. I've used this <?php if(!is_front_page()):?> function, but it is not working.
some one suggest me <?php if(!is_home()):?>, but it is not working either.
So how do I make it work?
Please follow the below steps:
Dashborad > Settings > Reading
Select A static page (select below) option in Front page displays section.
Select the page you want to display from Front Page drop down box.
In header.php in the code for displaying menu, make the alteration as below.
if ( ! is_page( '{slug of the selected page in Front Page drop down box}' ) ) {
//enter your code to display menu here
}
?>

WooCommerce list view

I have a WordPress site with WooCommerce installed,
The problem I'm having is on the shop page the products are by default shown as a GRID (side by side), there's a button to switch from the default GRID mode to LIST mode; but for every new client that comes on the site, they would have to manually change it!
I'd like to permanently change the default view from GRID to LIST for every person that comes on the site, but I can't find any way to do this in the code.
Does anyone have any knowledge on how to do this?
There is a plugin that can do this for you: http://wordpress.org/plugins/woocommerce-grid-list-toggle
After installing the plugin go to your dashboard: Woocommerce -> Settings -> product -> Scroll to the bottom of the page and there is an option called Default catalog view, change that from Grid to List.
There will be an option for users on the shop page to change the view from List to Grid. To hide this option add the following to the CSS:
.gridlist-toggle
{
display: none !important;
}
My solution can switch grid to list view as default on products page.
You can try this:
Connect to your FTP/public_html/wp-content/YOUR_THEME/woocommerce/global/
Edit wrapper-start.php
You will see this code
$shop_view = shopme_get_meta_value('shop_view');
if (empty($shop_view)) { $shop_view = 'view-grid'; }
if (!empty( $shop_view ) ) { $wrapper_classes[] = $shop_view; }
Replace "view-grid" to "list_view_products"
I just solved the same problem.
This is my solution how to PERNAMENTLY force WooCommerce to show product catalog only as List View.
JS
// This will remove class="grid" on page load and add class="list" to your product view
$(document).ready(function(){
$('.browse-view ul#products').removeClass('grid').addClass('list');
});
JS -- Test with Woocommerce v4.0.1
// -- Last Rev. (2020-04) --
jQuery(function($){
$('.woocommerce ul.products').removeClass('grid').addClass('list');
});
CSS
/* This will hide grid/list switcher in toolbar*/
.view-mode{display:none!important;}
Another way to do this is use this plugin: https://wordpress.org/plugins/gridlist-view-for-woocommerce/
After install go to settings WooCommerce -> Grid/List View
In Buttons tab change Default style to List and uncheck all in Buttons display
In Products Count tab uncheck Use products count

Custom set "current-menu-item" class for specific pages in WP

I'm creating a custom WP theme and I'm using the Wordpress navigation bar. When switching between different pages, WP adds a "current-menu-item" class to link in navigation bar which corresponds to the current page.
However, if that page/post is not present in the nav bar, it doesn't add the "current-menu-item" to any of the nav bar items.
My problem is, when a user visits the page "BLOG" (which is actually a category page) and clicks on a certain post which opens the single.php template, I want the nav bar item "BLOG" to be underlined as it would if the visitor was visiting a blog page.
Sometimes I will want another nav bar item to be underlined when landing on SINGLE, depending on where the user came from (I also have homepage posts, then I'd like HOME to be underlined)
How do I accomplish this? Thanks.
You can use a filter and check what page you are currently on using conditional statements and add classes before the menu gets displayed:
function add_custom_classes($classes, $item){
if(is_single() && $item->title == 'BLOG'){
$classes[] = 'current-menu-item';
}
return $classes;
}
add_filter('nav_menu_css_class' , 'add_custom_classes' , 10 , 2);

Resources