krishnathamisetty
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: Slug with same name throws 404 when new slug is in draft modeThis “wp_unique_post_slug” hook code will take care of unique post when user try to enter the same slug when it is in draft mode otherwise it will prompt error message:
add_filter( 'wp_unique_post_slug', 'post_unique_slug', 10, 6); function post_unique_slug( $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ){ if ($post_type == 'post'){ global $wpdb, $post; $post = get_post($post_ID); $check_sql = "SELECT post_title FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1"; $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $original_slug, $post_type, $post_ID ) ); if ( $post_name_check ){ echo '<script>document.addEventListener("DOMContentLoaded", function(event) {alert("Already exists with same article - '.$post_name_check.'")});</script>'; $error_message = '<span style="color:red">Already exists with same article - '.$post_name_check.'</span>'; add_settings_error('duplicate_slug', 'duplicate_slug', $error_message, 'error'); settings_errors( 'duplicate_slug' ); $post->post_name = ''; $post->post_status = 'draft'; wp_update_post($post); return $original_slug; } } return $slug; }- This reply was modified 6 years, 5 months ago by krishnathamisetty.
- This reply was modified 6 years, 5 months ago by Steven Stern (sterndata).
Forum: Fixing WordPress
In reply to: Slug with same name throws 404 when new slug is in draft modeI knew this… but how end user will come to know that there is another slug with same name exists when he is in draft mode… It should prompt warning message… that makes end user job easy.
Also add following code to replace link path for previous and next links
$next_image_link = str_replace(‘image/’, ”, $next_image_link)
$prev_image_link = str_replace(‘image/’, ”, $prev_image_link)File Name: /nextgen-gallery/products/photocrati_nextgen/modules/nextgen_basic_imagebrowser/package.module.nextgen_basic_imagebrowser.php
in render_image_browser method
after below line add above two lines
$next_image_link = $this->object->remove_param_for($next_image_link, ‘show’, $displayed_gallery->id());- This reply was modified 6 years, 11 months ago by krishnathamisetty.
Hi @dglassman,
Through program you can remove ‘/image/’ part.
1. File Name: /nextgen-gallery/products/photocrati_nextgen/modules/nextgen_basic_imagebrowser/package.module.nextgen_basic_imagebrowser.php
At the end of the file, you will find following code
class A_NextGen_Basic_ImageBrowser_Urls extends Mixin
{
function create_parameter_segment($key, $value, $id = NULL, $use_prefix = FALSE)
{
if ($key == ‘pid’) {
return “image/{$value}”;
} else {
return $this->call_parent(‘create_parameter_segment’, $key, $value, $id, $use_prefix);
}
}
}Solution: Change from
return “image/{$value}”;
to
return “{$value}”;2. File Name: nextgen-gallery/products/photocrati_nextgen/modules/nextgen_basic_imagebrowser/module.nextgen_basic_imagebrowser.php
Line # 101, you will find following method
function define_routes($router)
{
$slug = ‘/’.C_NextGen_Settings::get_instance()->router_param_slug;
$router->rewrite(“{*}{$slug}{*}/image/{\\w}”, “{1}{$slug}{2}/pid–{3}”);
}
Solution: Change from
$router->rewrite(“{*}{$slug}{*}/image/{\\w}”, “{1}{$slug}{2}/pid–{3}”);
to
$router->rewrite(“{*}{$slug}{*}/{\\w}”, “{1}{$slug}{2}/pid–{3}”);Hope this will helps you for your requirement.
Krishna
@tazotodua, you can use rewrite method
add_action(‘init’, ‘rewrite_url’);
function rewrite_url(){
add_rewrite_rule(‘^(.*)?’,’index.php?rest_route=/$matches[1]’, ‘top’);
flush_rewrite_rules();
}Append above code in functions.php
This will remove wp-json or hide wp-json from url while calling rest apiafter got the results comment below line.
flush_rewrite_rules();- This reply was modified 6 years, 11 months ago by krishnathamisetty.
Hi @gabyimagely ,
I am also looking for the solution which was raised by @dglassman, to remove “nggallery/image” from the url.
@dglassman Any help will be more thankful.
example:
It’s currently:
https://sample.com/gallery-test/nggallery/image/(image name)I want:
https://sample.com/gallery-test/(image name)Krishna