Replace author url with different one (wordpress) - wordpress

There are 3 authors in our company blog, each author has own site url in profile settings:
Mike - http://mike.com
Gelens - http://gelens.com
Admin - http://site.com/company/
the links for profiles are:
http://site.com/author/Mike/
http://site.com/author/Gelens/
http://site.com/author/Admin/
I need to replace a link to Admin's page, so, if there is <?php the_author_posts_link(); ?> tag on some page, and the author is Admin, the link must be http://site.com/company/ instead of http://site.com/author/Admin/.
How can I do that?

It looks like the the_author_posts_link function just calls get_author_posts_url to get the link, which passes the link through the author_link filter before returning it. In your theme's functions.php, you could add something like this (untested):
add_filter( 'author_link', 'admin_author_link', 10, 3);
function admin_author_link($link, $author_id, $author_nicename) {
if( $author_id==1 ) {
$link = 'http://site.com/company/';
}
return $link;
}

I think the least heartburn would be wordpress > the_author_meta.
Have each user add their url in the wordpress user profile, as you have done. Then in your theme's functions.php use the_author_meta('user_url'). Remember this will echo the url. To use it as a variable use get_the_author_meta('user_url').
Here is how we did it with the twenty ten theme, this is in functions.php
function twentyten_posted_on() {
printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
'meta-prep meta-prep-author',
sprintf( '<span class="entry-date">%3$s</span>',
get_permalink(),
esc_attr( get_the_time() ),
get_the_date()
),
sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
get_the_author_meta('user_url'), //changed from get_author_posts_url( get_the_author_meta( 'ID' ) ),
sprintf( esc_attr__( 'About %s', 'twentyten' ), get_the_author() ),
get_the_author()
)
);
}

That's URL rewriting with .htaccess, which is possible by editing the .htaccess by hand.
But easier for a beginner with a plugin such as http://wordpress.org/extend/plugins/redirection/ which seems like it will do what you need.

You can do this using http rewrites.

I also needed author URL to a different page.
My site is on WordPress and I use oxygen.
I went to my blog page template where I entered the author which is selected dynamically.
there is an option to link the author's name to the archive page or the author's website.
I selected the author's website. Then went to the users on WordPress and went to the authors and added the page I wanted to actually go to as their website.

Related

How to change the default URL of PublishPress Authors from "author" to "members"?

On a WordPress website I'm using BuddyBoss theme and I've added a glossary plugin.
I'm trying to add a Author Box to under each glossary term, to let site visitors visit the profile of its author. To do this, I've installed a plugin called PublishPress which almost does the job but by default the profile URLs leads to the person's author profile https://example.com/author/hisname/ which should be https://example.com/members/hisname/.
By googling I found a similar solution for another theme:
// FUNCTION
// Change Post's Author URL to Buddypress Profile URL
add_filter('generate_post_author_output','generate_post_author_output_buddyprss_url');
function generate_post_author_output_buddyprss_url( $post_author_profile_link ){
$post_author_profile_link = sprintf( ' <span class="byline">%1$s</span>',
sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s <a class="url fn n" href="%2$s" title="%3$s" rel="author" itemprop="url"><span class="author-name" itemprop="name">%4$s</span></a></span>',
__( 'by','generatepress'),
esc_url( bp_core_get_user_domain( get_the_author_meta( 'ID' ) ) ),
esc_attr( sprintf( __( 'Know more about %s', 'generatepress' ), get_the_author() ) ),
esc_html( get_the_author() )
)
) ;
return $post_author_profile_link;
}
I'm wondering how can I customize the script in order to do the exact job. To be honest I'm totally screwed up. Thanks for any help!
I fixed the issue by the pro version of the PublishPress Authors. In the pro version there's a possibility to edit the layout and there's a property returning the BuddyPress Profile Link.
<a href="{{ author.buddypress_profile_link }}"...
instead of:
<a href="{{ author.link }}"...

Looking for query to get meta_value

So i'm using Wordpress, Woocommerce and the "Product Video for WooCommerce" plugin by Addify. The URL to a mp4 video is stored in the:
wp_postmeta table
In this table, the post_id matches the product.
In the "meta_value" i can see the URL i've added.
No my question;
I want to place a download button that downloads the video stored in this location.
I've located the woocommerce hook where the button needs to come, but I can't figure out how to fetch the url from this meta_value.
My code skills are very basic so this is to complicated for me.
Can anyone help me out on this?
This showed me that the URL is visible but surely not the end goal :-)
add_filter( 'woocommerce_share', 'custom_button', 20 );
function custom_button() {
$meta = get_post_meta(get_the_ID(), '', true);
print_r($meta);
}
//Here I want to add the button
print '<button>Download video</button>';
Thanks!
'woocommerce_share' hook is an action, not filter.
Try this
add_action( 'woocommerce_share', 'custom_button', 20 );
function custom_button() {
$download_url = get_post_meta(get_the_ID(), 'afpv_cus_featured_video_id', true);
if ( empty( $download_url ) ) { // do not print anything if download_url doesn't exists
return;
}
// print the download button
printf( '<a href="%s" class="button" target="_blank" download>%s</a>',
esc_url( $download_url ),
__( 'Download video', 'text-domain' ) // string can be translated, change text-domain by the theme domain or plugin domain
);
}

Pop Up Comment Box In wordpress

I Want to show pop up box on my Wordpress blog when someone want to make a comment in archive file , like i have "Leave a Comment" link in my index file and when user click on that it should be pop up with comment box rather than redirect to single post page
i have tried many Plugins but nothing works
this is my code in Wordpress
<?php comments_popup_link( __( 'Leave a comment', 'beautytemple' ), __( '1 Comment', 'beautytemple' ), __( '% Comments', 'beautytemple' ) ); ?>
If we are using comments_popup_link() function. We have to use the_loop, have_posts() ,the_post(). The comments_popup_link() will only work when we are using this function within the loop.

Customize the search results page in a Wordpress Genesis child theme

I am using Wordpress and the Genesis framework for a site. I'm using a child theme (Ayoshop - not that it matters much) for the theme. I would like to customize the search results page by removing the 'post info' area where it shows the date, author, and 'leave a comment' link, and instead show the featured image for that post. The theme is using the search.php page from the Genesis theme, so I'm not really sure how to proceed in how to customize it.
Here is the code from the Genesis theme search.php:
add_action( 'genesis_before_loop', 'genesis_do_search_title' );
/**
* Echo the title with the search term.
*
* #since 1.9.0
*/
function genesis_do_search_title() {
$title = sprintf( '<div class="archive-description"><h1 class="archive-title">%s %s</h1></div>', apply_filters( 'genesis_search_title_text', __( 'Search Results for:', 'genesis' ) ), get_search_query() );
echo apply_filters( 'genesis_search_title_output', $title ) . "\n";
}
genesis();
It actually did matter that it was the Ayoshop theme, there was a custom filter that was added in a file called theme-tweaks.php that removed the original post info and added a custom post info, so I needed to remove that custom action.
All of the changes were done in the functions.php file.
I made sure to remove the genesis_post_info, and then removed the custom action that Ayoshop added.
remove_action( 'genesis_before_post_content', 'genesis_post_info' );
remove_action( 'genesis_before_post_content', 'ayo_post_info' );
I then added an action to add the image to the post.
add_action ( 'genesis_before_post_content', 'jl_post_info' );
function jl_post_info()
if ( has_post_thumbnail() ) {
printf( '<div class="post-info">' . get_the_post_thumbnail() . '</div>');
}
}

How to remove the author name on wordpress blog posts?

I want to remove the author name from wordpress blog posts . Also I dont want to delete the author name becoz I use different author names from admin side.
WP v4.1.2
Edit content-single.php:
Appearance->Editor->content-single.php
<div class="entry-meta">
<?php // twentyeleven_posted_on(); ?>
</div><!-- .entry-meta -->
Comment the middle line "twentyeleven_posted_on();" like above
Title line on post saying: Published By AUTHOR on DATE will not be displayed
OR (less recommended as it effects a wider scale)
functions.php
COMMENTED LINE get_the_author()
function twentyeleven_posted_on() {
printf( __( '<span class="sep">Posted on </span><time class="entry-date" datetime="%3$s" pubdate>%4$s</time><span class="by-author"> <span class="sep"> by </span> <span class="author vcard"><a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a></span></span>', 'twentyeleven' ),
esc_url( get_permalink() ),
esc_attr( get_the_time() ),
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
esc_attr( sprintf( __( 'View all posts by %s', 'twentyeleven' ), get_the_author() ) )/*,
get_the_author()*/
);
}
Open the single.php file of your current theme through your ftp client or from Dashboard -->Appearance -->Editor
Delete this code :
<span class="meta_author"><?php the_author(); ?></span>
Hope this helps
You can comment/delete the line where author name is printed.
<span class="meta_author"><?php the_author(); ?></span>
I removed the author names from posts and search results on a site built with The7 theme by adding this custom CSS:
a.author.vcard {
display: none;
}
The other answers here that relate to the PHP code of WP are true, but alternatively this can also be done by modifying the CSS code of the site.
Under the main stylesheet file (style.css), you can add this definition:
.blog-title-body SPAN {
display:none !important;
}
This specifically will hide both the author name AND the category name under the header of the post page (the post name).
If you want to remove only the category name, for example, you can put in the following definition:
.blog-title-body SPAN.cat-links {
display:none !important;
}
NOTE:
be sure to always make a backup copy of every built-in file on WP site that you modify!!
It is also highly recommended to make an entire site backup periodically, with and without relation to modifications and changes.

Resources