- This topic has 7 replies, 3 voices, and was last updated 2 years, 11 months ago by
Martin.
-
AuthorPosts
-
February 6, 2020 at 2:34 pm #1157129
Martin
Hi,
I would like to be able to specify a different HOME URL for when a user is logged in. This would be very useful for my Members Website, where I need to top LOGO IMAGE URL to point to a PREVIEW page when users are logged out (website home url) and a MEMBERS URL (for logged in users).Is there a CSS I can use? Or any other simple trick?
Thank you!
Martin
February 6, 2020 at 3:32 pm #1157170Leo
StaffCustomer SupportHi there,
CSS can only change the visual side of things so cannot be used to change the URL.
The theme itself doesn’t control the URL/permalink structure as well.
I would recommend checking with the membership plugin support to see they can point you in the right direction.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/February 7, 2020 at 5:14 am #1157725Martin
Thank you for the reply.
Perhaps you would know of a way to achieve this via the function.php file that I could add in a child theme of generatepress?February 7, 2020 at 5:39 am #1157775David
StaffCustomer SupportHi there,
Add this PHP snippet to your site:
add_action( 'wp', function() { if ( is_front_page() && is_user_logged_in() ) { wp_redirect( home_url( '/logged-in-home' ) ); die(); } } );
https://docs.generatepress.com/article/adding-php/
change
logged-in-home
to the page slug you want to redirect to.Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/February 7, 2020 at 6:05 am #1157805Martin
Finally I found a way to do it. I’m sharing it here in case someone in the future would like to do something similar.
1) Create a CHILD THEME from the used theme
2) In the Child Theme Folder:A) Edit functions.php, and add this code:
// shortcode to display content for loggedout and loggedin users : shortcodes are [loggedout] [loggedin]
add_shortcode( ‘loggedout’, ‘visitor_check_shortcode’ );
function visitor_check_shortcode( $atts, $content = null ) {
if ( ( !is_user_logged_in() && !is_null( $content ) ) || is_feed() )
return do_shortcode($content);
return ”;
}
add_shortcode( ‘loggedin’, ‘member_check_shortcode’ );
function member_check_shortcode( $atts, $content = null ) {
if ( is_user_logged_in() && !is_null( $content ) && !is_feed() )
return do_shortcode($content);
return ”;
}B) Copy the file header.php from your theme to the child theme.
Then edit header.php:
Add the following in the top of the header.php file, somewhere before <body>:<!– CUSTOM HOME URL ON GP LOGO IMAGE IF USER IS LOGGED-IN –>
<?php
if ( is_user_logged_in() ) {
add_filter( ‘generate_logo_href’,’generate_add_custom_logo_href’ );
function generate_add_custom_logo_href()
{
return ‘https://www.yourwebsite.com/logged-in-url’;
} else {
}
?>
<!– END CUSTOM HOME URL IF USER IS LOGGED-IN –>February 7, 2020 at 6:39 am #1157844David
StaffCustomer SupportGlad you found a solution and thanks for sharing
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/February 7, 2020 at 9:46 am #1158150Martin
Here’s a different approach I found, editing only the functions.php file in the child theme folder, which is preferred so the modification wont interfere with future updates of the main theme files:
Add this code to the functions.php file:
// LOGGED-IN USERS : HOME URL FOR TOP LOGO/HEADER IMAGE IN GENERATE PRESS
if ( is_user_logged_in() ) {
// set header logo image url when logged-in
add_filter( ‘generate_logo_href’,’generate_add_custom_logo_href’ );
function generate_add_custom_logo_href()
{
return ‘https://www.yourwebsite.com/logged-in-url/’;
}
}February 7, 2020 at 9:46 am #1158152Martin
I’ll mark this topic as resolved.
-
AuthorPosts
- You must be logged in to reply to this topic.