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?
Related
I have a Wordpress website
www.example.com
Once a user goes to URL he sees Wordpress login page and below URL in the browser address bar.
www.example.com/wp-admin/....
I want to change that so when people go www.example.com they see the login page and the url in the browser address bar remains same www.example.com or in other words I dont want that slug and redirect text seen in the address bar. Is that possible to do?
I don't know that you can rewrite wp-admin, but you could create your own login code to display on the Home page. To start with, wp_login_form() displays a login form:
<?php wp_login_form(); ?>
You could add this code to a page template, or create a shortcode so it can be added via the Dashboard editor like this:
add_action( 'init', 'stackoverflow_login_shortcode' );
function stackoverflow_login_shortcode() {
add_shortcode( 'stackoverflow-login-form', 'stackoverflow_login_form_shortcode' );
}
function stackoverflow_login_form_shortcode() {
if ( is_user_logged_in() ) {
return '<p>You are already logged in!</p>';
}
return wp_login_form( array( 'echo' => false ) );
}
Now you can add [stackoverflow-login-form] into a page.
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 );
I have an article with several pages in my wordpress blog. if for example i have the following link in my blog :
http://example.com/heartbreaking-photos
any idea how can i change the link of the second page from
http://example.com/heartbreaking-photos/2
to http://example.com/heartbreaking-photos/CUSTOM-STRING
CUSTOM-STRING aimed to be a custom title inside the page
To achieve this, you will need to do 2 things:
Disable the default WordPress canonical redirect - this is necessary, because WordPress will always redirect to the /2/ page when it encounters the page parameter in the URL or query args.
Add a custom rewrite rule to direct your custom title to the second page of your page - this is essentially necessary to allow the link format that you want.
In terms of code, this is what you need (this is a working solution, I've just tested it locally):
// Removes the canonical redirection
remove_filter( 'template_redirect', 'redirect_canonical' );
// Add custom rewrite rules
add_action( 'init', 'my_add_custom_rewrite_rules' );
function my_add_custom_rewrite_rules() {
// Slug of the target page
$page_slug = 'heartbreaking-photos';
// Page number to replace
$page_num = 2;
// Title you wish to replace the page number with
$title = 'custom-string';
// Add the custom rewrite rule
add_rewrite_rule(
'^' . $page_slug . '/' . $title . '/?$',
'index.php?pagename=' . $page_slug . '&page=' . $page_num, 'top'
);
}
There are three things you might want to configure or change here:
$page_slug - this is the slug of your page, in your case this is heartbreaking-photos
$page_num - the number of your pagination page, in your case this is 2
$title - the title you wish to use instead of your page number 2.
Feel free to alter the code as you wish, or copy it to cover more additional cases, similar to this one.
EDIT
Important: Once you use the code, go to Settings > Permalinks and click the "Save Changes" button. This will rebuild your rewrite rules, and is necessary for the solution to work.
Hope that helps. Let me know if you have any questions.
You can try this codex. Pass the arg and you will get page id, page title and use those
https://codex.wordpress.org/Function_Reference/get_pages
Or you can call page title by page id
$pagetitle= get_post_field( 'post_title', $page_id );
Ok, so basically you don't want to display the navigation link under the page (use css or modify the post template in the child theme) and add your custom link. If I understand it well:
Remove navigation links (depends on your theme, but basically):
.nav-links { display: none; }
You can add the custom link through function + custom fileds:
create a custom field, for example "my-url" in your post, see codex: https://codex.wordpress.org/Custom_Fields
add to your functions.php (in the child theme or in a custom site plugin):
function my_page_add_to_content( $content ) {
if ( ! empty(get_post_meta( get_the_ID(), 'my-url', true ) ) {
$content .= 'URL TEXT HERE'
}
return $content;
}
add_filter( 'the_content', 'my_page_add_to_content' );
I am trying to create a page test.php that can use wordpress functions but is not part of the admin/pages section. so basically if I have a link on my single.php or page.php to direct me to test.php not show the 404 but actually show me the contents of test.php. I've heard that i might have to make some changes to the htaccess but I'm not sure how to search for this issue so any help is greatly appreciated.
You can use include('../wp-load.php'); in the top of your php file to get wordpress functionality in to your file then place your file in the root wordpress installation and then you can call your file with your url http://yourdomain.net/test.php
The information for creating page templates, plugins and using functions.php can all be found on the WordPress site.
How to call wordpress functions in custom php script
if ( is_admin() ) {
add_action( 'admin_menu', array( 'adminAddPage' ) );
}
/**
* Callback to add page
*/
public function adminAddPage() {
add_options_page( 'Custom page title', 'Custom page title', 'manage_options', 'custom_page_slug', array('adminPage') );
}
/**
* Page HTML Callback
*/
public function adminPage() {
// your html code
}
I have http://mysite.com/admin.php
There I check wether the user is admin or not.
In second case I send the user to the wp-login page like this:
blog.mysite.com/wp-login.php?redirect_to=http%3A%2F%2Fmysite.com/admin.php
I expect redirect back for admin.php but wordpress always send me to wp-admin control panel.
I have researched.
When the dest. host is not in filter
allowed_redirect_hosts
WP just redirect the user to wp-admin.
How can I add more hosts to the filter?
If I put this example from the WP Codex on functions.php it stops working.
(http://codex.wordpress.org/Plugin_API/Filter_Reference/allowed_redirect_hosts)
add_filter( 'allowed_redirect_hosts' , 'my_allowed_redirect_hosts' , 10 );
function my_allowed_redirect_hosts($content){
$content[] = 'blog.example.com';
$content[] = 'codex.example.com';
// wrong: $content[] = 'http://codex.example.com';
return $content;
}
Add the following in your functions.php:
function my_allowed_redirect_hosts($allowed_host) {
$allowed_host[] = 'anothersite.com';
$allowed_host[] = 'www.someotherwebsite.com';
return $allowed_host;
}
add_filter('allowed_redirect_hosts','my_allowed_redirect_hosts');
Replace anothersite.com and add new values accordingly.
If you're trying to redirect users in a normal page, you can make use of Wordpress's wp_redirect() function:
<?php
wp_redirect( $location, $status );
exit;
?>
Documentation: wp_redirect()
Hope this helps!
Finally it works!
What I was doing wrong is putting the code in the WP functions.php file, and not in my custom theme functions.php file.
Thanks all!