I have added the code below to my functions.php to add a "Login" Link to my wp menu.
$newlink = '<li>' . $args->before . '<a title="Login" href="'. wp_login_url('index.php') .'">' . $args->link_before . 'Login' . $args->link_after . '</a>' . $args->after;
how can i change wp_login_url function to use another page? For example, I'm using the mingle plugin which creates a custom login page.
code below from wp-includes/general-template.php
function wp_login_url($redirect = '', $force_reauth = false) {
$login_url = site_url('wp-login.php', 'login');
if ( !empty($redirect) )
$login_url = add_query_arg('redirect_to', urlencode($redirect), $login_url);
if ( $force_reauth )
$login_url = add_query_arg('reauth', '1', $login_url);
return apply_filters('login_url', $login_url, $redirect);
}
I would not recommend changing the core code of WordPress as you will likely break the install.
Can you not just update your functions.php file line of code to be something like:
$newlink = '<li>' . $args->before . '<a title="Login" href="/login/">' . $args->link_before . 'Login' . $args->link_after . '</a>' . $args->after;
Related
I am trying to display a grid list of registered users under specific roles such as subscriber, editor, etc with custom metadata. I've started with this below code but it only displays the avatar and the name when need to display some more data of each user such as website link, description, email.
Here is the code snippet I am using-
function wpb_recently_registered_users() {
global $wpdb;
$recentusers = '<ul class="recently-user">';
$usernames = $wpdb->get_results("SELECT user_nicename, user_url, user_email FROM $wpdb->users ORDER BY ID DESC LIMIT 5");
foreach ($usernames as $username) {
if (!$username->user_url) :
$recentusers .= '<li>' . get_avatar($username->user_email, 45) . '' . $username->user_nicename . "</li>";
else :
$recentusers .= '<li>' . get_avatar($username->user_email, 45) . '' . $username->user_nicename . "</li>";
endif;
}
$recentusers .= '</ul>';
return $recentusers;
}
add_shortcode('wpb_newusers', 'wpb_recently_registered_users');
I need to get these user meta key data also -
mepr_email, mepr_your_bio, mepr_youtube_channel
but not sure how to integrate with the above code snippets. Can anyone help me find a better solution, please?
So I am using this code snippet and getting all the required data but I am not sure how to run this as a loop so as soon as a new user register it will get the data like posts query? Sorry I have limited knowledge in this.
'function user_data_code(){
$blogusers = get_users( array( 'search' => 'admin' ) );
// Array of WP_User objects.
foreach ( $blogusers as $user ) {
echo '<span>' . get_avatar($user->user_email, 45) . '</span> <br>';
echo '<span>' . esc_html( $user->user_email ) . '</span> <br>';
echo '<span>' . esc_html( $user->display_name ) . '</span> <br>';
echo '<span>' . esc_html( $user->first_name ) . '</span> <br>';
echo '<span>' . esc_html( $user->mepr_bio ) . '</span> <br>';
echo '<span>' . esc_html( $user->mepr_website_link) . '</span>';
}
}
add_shortcode('wpb_newusers', 'user_data_code');'
I have a Multisite installation:
1: The main site - domain.com
2: other sites - domain.com/some-url
FIXED: So far so good. My script shows the content automatically below the header and not where my shortcode is inserted.
function subsites_list_sites() {
$subsites = get_sites();
if ( ! empty ( $subsites ) ) {
echo '<div class="subsites-container">';
foreach( $subsites as $subsite ) {
$subsite_id = get_object_vars( $subsite )["blog_id"];
$subsite_name = get_blog_details( $subsite_id )->blogname;
$subsite_link = get_blog_details( $subsite_id )->siteurl;
echo '<div class="subtite-item site-' . $subsite_id . '">
<a class="thumb" href="' . $subsite_link . '">Here i want the featured image/thumbnail to display</a>
<a class="title-link" href="' . $subsite_link . '"><h3 class="title">' . $subsite_name . '</h3></a>
<a class="excerpt" href="' . $subsite_link . '"><p>Here i want excerpt<p></a>
<a class="btn-link" href="' . $subsite_link . '">GO TO WEBSITE</a>
</div>';
}
echo '</div>';
}
}
add_shortcode( 'subsites_list_sites_sc', 'subsites_list_sites' );
Shortcodes should return the html not print it in the shortcode function.
Try like this:
function subsites_list_sites() {
$subsites = get_sites();
$returnHtml = '';
if ( ! empty ( $subsites ) ) {
$returnHtml .= '<div class="subsites-container">';
foreach( $subsites as $subsite ) {
$subsite_id = get_object_vars( $subsite )["blog_id"];
$subsite_name = get_blog_details( $subsite_id )->blogname;
$subsite_link = get_blog_details( $subsite_id )->siteurl;
$returnHtml .= '<div class="subtite-item site-' . $subsite_id . '">
<a class="thumb" href="' . $subsite_link . '">Here i want the featured image/thumbnail to display</a>
<a class="title-link" href="' . $subsite_link . '"><h3 class="title">' . $subsite_name . '</h3></a>
<a class="excerpt" href="' . $subsite_link . '"><p>Here i want excerpt<p></a>
<a class="btn-link" href="' . $subsite_link . '">GO TO WEBSITE</a>
</div>';
}
$returnHtml .= '</div>';
}
return $returnHtml;
}
Output
The return value of a shortcode handler function is inserted
into the post content output in place of the shortcode macro. Remember
to use return and not echo - anything that is echoed will be output to
the browser, but it won't appear in the correct place on the page.
https://codex.wordpress.org/Shortcode_API#Output
Have since a small module (wordpress) that does not automatically more language can.
Since WPML finds no string.
$html .= '<li class="weiterlesen">' . $args['readmore_text'] . '</li></ul></div>';
replace . $args['readmore_text'] . to <?php _e( 'readmore', 'tpl' ); ?>
Try below code
$html .= '<li class="weiterlesen">' . __( 'readmore', 'tpl' ) . '</li></ul></div>';
I am new to PHP, currently getting error saying
Fatal error: Call to a member function url() on a non-object on line 8
Below is the code I am trying
<?php
$subpages = $site->pages()->children()->visible();
$image_url = $subpages->image()->url();
$title = $subpage->title()->text();
foreach($subpages as $subpage) {
echo '<div class="col-md-4">';
echo '<h2>' . $title . '</h2>';
echo '<a href="' . $subpage->url() . '" title="' . $title . '">';
echo '<img src="' . $image_url . '" alt="' . $title . '" class="img-responsive img-thumbnail">';
echo '</a>';
echo '</div>';
}
?>
Here's your code corrected:
<?php
$subpages = $site->children()->visible();
foreach($subpages as $subpage) {
$image_url = $subpage->image()->url();
$title = $subpage->title()->html();
echo '<div class="col-md-4">';
echo '<h2>' . $title . '</h2>';
echo '<a href="' . $subpage->url() . '" title="' . $title . '">';
echo '<img src="' . $image_url . '" alt="' . $title . '" class="img-responsive img-thumbnail">';
echo '</a>';
echo '</div>';
}
?>
What's wrong with your code:
You should use $site->children() to list all children of the site
See kirby docs
You're defining $image_url and $title before the foreach which is not correct. I moved them just at the beginning of the foreach
loop. Also corrected image_url to use subpage instead of subpages.
You're using text() on your title. That doesn't exist, use either kirbytext() or html() depending on what you want to do. See the
docs.
You should check what are the values and methods in $subpages? i think there is problem when you assigning the values to the variable.
I'm trying to highlight a menu item depending if it's on the current page. The code below is currently highlighting every menu item because it's within the foreach loop. How can I highlight the taxonomy term if it's on a certain page id and ONLY that term (not every one)?
<?php $args = array( 'taxonomy' => 'blog' );
$terms = get_terms('blog', $args);
$count = count($terms); $i=0;
if ($count > 0) {
$cape_list = '<p class="my_term-archive">';
echo $postid;
foreach ($terms as $term) {
$i++;
$absolute = get_bloginfo('url');
$postid = get_the_ID();
if($postid == "561") {
$term_list .= '<a class="menu-active" style="padding-left:30px;width:88%!IMPORTANT;" href="' . $absolute . '/blog/' . $term->slug . '" title="' . sprintf(__('View all post filed under %s', 'my_localization_domain'), $term->name) . '">' . $term->name . '</a>';
} else {
$term_list .= '<a style="padding-left:30px;width:88%!IMPORTANT;" href="' . $absolute . '/blog/' . $term->slug . '" title="' . sprintf(__('View all post filed under %s', 'my_localization_domain'), $term->name) . '">' . $term->name . '</a>';
} } ?>
<?php echo $term_list; } ?>
You will have to query the taxonomy terms belonging to the current page and compare their id-s in the foreach loop.
The get_the_ID() function returns the id of the current post, not the current taxonomy.
Here is a link to a wordpress related question which shows how you can query current taxonomy terms:
https://wordpress.stackexchange.com/questions/20431/how-to-get-taxonomy-term-of-the-current-page-and-populate-queries-in-the-templat