Forum Replies Created

Viewing 15 replies - 1 through 15 (of 19 total)
  • Thread Starter panhwerwaseem121

    (@panhwerwaseem121)

    Thank you so much for your quick reply! will discussed it with my team and get back to you if any more assistance is required

    Thread Starter panhwerwaseem121

    (@panhwerwaseem121)

    Still waiting for your response!

    Thread Starter panhwerwaseem121

    (@panhwerwaseem121)

    Its working fine please check it, because i just open it and it working fine kindly please check again: https://streamable.com/31bf2k

    Thread Starter panhwerwaseem121

    (@panhwerwaseem121)

    here is first video: https://streamable.com/31bf2k
    here is second video: https://streamable.com/qkr38j

    in both videos you will see I’m opening another blog but opening different content in blog please tell me how to solve this problem because this is going to be a big disaster for my website.

    Thread Starter panhwerwaseem121

    (@panhwerwaseem121)

    It was issue in the old update, and issue in recent update also, actually before i have the old version getting same issue i thought to update the plugin after update i again getting same issue, i also talk to WPML they said this is amp side issue you need to talk AMP team can you please check and let me know why this issue is keep producing in language pages.

    Thread Starter panhwerwaseem121

    (@panhwerwaseem121)

    @johnny5 can you please explain how i can create target URL with Regular expression in redirection tool, your sample code will be appreciated because i am getting confused in regular expressions how data from Source URL will go to target URL, your help is appreciated

    Thread Starter panhwerwaseem121

    (@panhwerwaseem121)

    We will add a JavaScript where it will add channel data to source url and when page load it automatically add channel to all respective source url, i reach on this step now channel data is adding to source url but when someone click on it, it will take to 404 or simple target link without adding channel attribute in target URL as you told in above messages

    Thread Starter panhwerwaseem121

    (@panhwerwaseem121)

    @johnny5 again I’m confused how channel attribute from source URL will go to target URL can you create a dummy regular expression as per my case and share here a dummy source URL and dummy target URL.

    Channel data will come from javascript, it will add current page slug in channel data.

    Thread Starter panhwerwaseem121

    (@panhwerwaseem121)

    I am sending you an Images please let me know how I pass attribute from source URL to target URL

    see image below: https://prnt.sc/11szqhy

    tell me how i can add regular expression to pass dynamic query parameters.

    Thread Starter panhwerwaseem121

    (@panhwerwaseem121)

    @johnny5 this is because we want to pass a channel attribute to our affilate panel, if we add a channel attribute in the end of target URL it will help us to identify from which page we get sales.

    I’m trying to add dynamic channel attribute in target URL let suppose if some user click my affliate like from page A then channel will be = page A or if someone click affliate linke from paage B then target URL have channel page B so i will update query parameter dynamically please help me out to fix this and let me know how i can achieve this using your plugin or any custom java-script

    Thread Starter panhwerwaseem121

    (@panhwerwaseem121)

    @ahmedkaludi can you help me to do this: 1. Either you create a custom rewrite rule for this permalink

    because i can’t found a way to do this kind of stuff looking forward for your response

    Thread Starter panhwerwaseem121

    (@panhwerwaseem121)

    @reneesoffice we are using your plugin let me send you one screenshot: https://snipboard.io/wrtGDd.jpg also every-page have your plugin is activated let me tell you one more thing:
    that those post redirecting to non-amp version are child post like:
    Parent Post: https://www.vpnranks.com/reviews/vyprvpn/
    Child Post: https://www.vpnranks.com/reviews/vyprvpn/kodi/
    Parent post AMP version working fine but child post amp redirecting to non-amp i am sending you code which i use to create this custom posts hierarchy.

    add_action('registered_post_type', 'make_posts_hierarchical', 10, 2 );
    
    // Runs after each post type is registered
    function make_posts_hierarchical($post_type, $pto){
    
        // Return, if not post type posts
        if ($post_type != 'post') return;
    
        // access $wp_post_types global variable
        global $wp_post_types;
    
        // Set post type "post" to be hierarchical
        $wp_post_types['post']->hierarchical = 1;
    
        // Add page attributes to post backend
        // This adds the box to set up parent and menu order on edit posts.
        add_post_type_support( 'post', 'page-attributes' );
    
    }
    
    /**
     * Get parent post slug
     *
     * Helpful function to get the post name of a posts parent
     */
    function get_parent_post_slug($post) {
        if (!is_object($post) || !$post->post_parent) {
            return false;
        }
    
        return get_post($post->post_parent)->post_name;
    }
    
    /**
     *
     * Edit View of Permalink
     *
     * This affects editing permalinks, and $permalink is an array [template, replacement]
     * where replacement is the post_name and template has %postname% in it.
     *
     **/
    add_filter('get_sample_permalink', function($permalink, $post_id, $title, $name, $post) {
        if ($post->post_type != 'post' || !$post->post_parent) {
            return $permalink;
        }
    
        // Deconstruct the permalink parts
        $template_permalink = current($permalink);
        $replacement_permalink = next($permalink);
    
        // Find string
        if(!is_amp_endpoint()) {
            $postname_string = '/%postname%/';
        }else{
            $postname_string = '/%postname%/amp/';
        }
    
        // Get parent post
        $parent_slug = get_parent_post_slug($post);
    
        $altered_template_with_parent_slug = '/' . $parent_slug . $postname_string;
        $new_template = str_replace($postname_string, $altered_template_with_parent_slug, $template_permalink);
    
        $new_permalink = [$new_template, $replacement_permalink];
    
        return $new_permalink;
    }, 99, 5);
    
    /**
     * Alter the link to the post
     *
     * This affects get_permalink, the_permalink etc.
     * This will be the target of the edit permalink link too.
     *
     * Note: only fires on "post" post types.
     */
    add_filter('post_link', function($post_link, $post, $leavename){
    
        if ($post->post_type != 'post' || !$post->post_parent) {
            return $post_link;
        }
    
        $parent_slug = get_parent_post_slug($post);
        $new_post_link = str_replace($post->post_name, $parent_slug . '/' . $post->post_name, $post_link);
    
        return $new_post_link;
    }, 99, 3);
    
    /**
     * Before getting posts
     *
     * Has to do with routing... adjusts the main query settings
     *
     */
    add_action('pre_get_posts', function($query){
        global $wpdb, $wp_query;
    
        $original_query = $query;
        $uri = $_SERVER['REQUEST_URI'];
    
        // Do not do this post check all the time
        if ( $query->is_main_query() && !is_admin()) {
    
            // get the post_name
            $basename = basename($uri);
            // find out if we have a post that matches this post_name
            $test_query = sprintf("select * from $wpdb->posts where post_type = '%s' and post_name = '%s';", 'post', $basename);
            $result = $wpdb->get_results($test_query);
    
            // if no match, return default query, or if there's no parent post, this is not necessary
            if (!($post = current($result)) || !$post->post_parent) {
                return $original_query;
            }
    
            // get the parent slug
            $parent_slug = get_parent_post_slug($post);
            // concat the parent slug with the post_name to get most of the url
            $hierarchal_slug = $parent_slug . '/' . $post->post_name;
    
            // if the concat of parent-slug/post-name is not in the uri, this is not the right post.
            if (!stristr($uri, $hierarchal_slug)) {
                return $original_query;
            }
    
            // pretty high confidence that we need to override the query.
            $query->query_vars['post_type'] = ['post'];
            $query->is_home     = false;
            $query->is_page     = true;
            $query->is_single   = true;
            $query->queried_object_id = $post->ID;
            $query->set('page_id', $post->ID);
    
            return $query;
        }
    
    }, 1);
    

    this file added in function.php, i think because of child permalink that amp redirect to non-amp can you help us with this???

    Thread Starter panhwerwaseem121

    (@panhwerwaseem121)

    @ahmedkaludi I’m Waiting for your response kindly let me know if you have some kind of solution for that problem, i think that issue is because of Child post permalink can you help us out thanks

    Thread Starter panhwerwaseem121

    (@panhwerwaseem121)

    @ahmedkaludi no i haven’t done any kind of redirection 301 on these pages but i want to tell you one more thing that those post redirecting to non-amp version are child post like:
    Parent Post: https://www.vpnranks.com/reviews/vyprvpn/
    Child Post: https://www.vpnranks.com/reviews/vyprvpn/kodi/
    Parent post AMP version working fine but child post amp redirecting to non-amp i am sending you code which i use to create this custom posts hierarchy.

    add_action('registered_post_type', 'make_posts_hierarchical', 10, 2 );
    
    // Runs after each post type is registered
    function make_posts_hierarchical($post_type, $pto){
    
        // Return, if not post type posts
        if ($post_type != 'post') return;
    
        // access $wp_post_types global variable
        global $wp_post_types;
    
        // Set post type "post" to be hierarchical
        $wp_post_types['post']->hierarchical = 1;
    
        // Add page attributes to post backend
        // This adds the box to set up parent and menu order on edit posts.
        add_post_type_support( 'post', 'page-attributes' );
    
    }
    
    /**
     * Get parent post slug
     *
     * Helpful function to get the post name of a posts parent
     */
    function get_parent_post_slug($post) {
        if (!is_object($post) || !$post->post_parent) {
            return false;
        }
    
        return get_post($post->post_parent)->post_name;
    }
    
    /**
     *
     * Edit View of Permalink
     *
     * This affects editing permalinks, and $permalink is an array [template, replacement]
     * where replacement is the post_name and template has %postname% in it.
     *
     **/
    add_filter('get_sample_permalink', function($permalink, $post_id, $title, $name, $post) {
        if ($post->post_type != 'post' || !$post->post_parent) {
            return $permalink;
        }
    
        // Deconstruct the permalink parts
        $template_permalink = current($permalink);
        $replacement_permalink = next($permalink);
    
        // Find string
        if(!is_amp_endpoint()) {
            $postname_string = '/%postname%/';
        }else{
            $postname_string = '/%postname%/amp/';
        }
    
        // Get parent post
        $parent_slug = get_parent_post_slug($post);
    
        $altered_template_with_parent_slug = '/' . $parent_slug . $postname_string;
        $new_template = str_replace($postname_string, $altered_template_with_parent_slug, $template_permalink);
    
        $new_permalink = [$new_template, $replacement_permalink];
    
        return $new_permalink;
    }, 99, 5);
    
    /**
     * Alter the link to the post
     *
     * This affects get_permalink, the_permalink etc.
     * This will be the target of the edit permalink link too.
     *
     * Note: only fires on "post" post types.
     */
    add_filter('post_link', function($post_link, $post, $leavename){
    
        if ($post->post_type != 'post' || !$post->post_parent) {
            return $post_link;
        }
    
        $parent_slug = get_parent_post_slug($post);
        $new_post_link = str_replace($post->post_name, $parent_slug . '/' . $post->post_name, $post_link);
    
        return $new_post_link;
    }, 99, 3);
    
    /**
     * Before getting posts
     *
     * Has to do with routing... adjusts the main query settings
     *
     */
    add_action('pre_get_posts', function($query){
        global $wpdb, $wp_query;
    
        $original_query = $query;
        $uri = $_SERVER['REQUEST_URI'];
    
        // Do not do this post check all the time
        if ( $query->is_main_query() && !is_admin()) {
    
            // get the post_name
            $basename = basename($uri);
            // find out if we have a post that matches this post_name
            $test_query = sprintf("select * from $wpdb->posts where post_type = '%s' and post_name = '%s';", 'post', $basename);
            $result = $wpdb->get_results($test_query);
    
            // if no match, return default query, or if there's no parent post, this is not necessary
            if (!($post = current($result)) || !$post->post_parent) {
                return $original_query;
            }
    
            // get the parent slug
            $parent_slug = get_parent_post_slug($post);
            // concat the parent slug with the post_name to get most of the url
            $hierarchal_slug = $parent_slug . '/' . $post->post_name;
    
            // if the concat of parent-slug/post-name is not in the uri, this is not the right post.
            if (!stristr($uri, $hierarchal_slug)) {
                return $original_query;
            }
    
            // pretty high confidence that we need to override the query.
            $query->query_vars['post_type'] = ['post'];
            $query->is_home     = false;
            $query->is_page     = true;
            $query->is_single   = true;
            $query->queried_object_id = $post->ID;
            $query->set('page_id', $post->ID);
    
            return $query;
        }
    
    }, 1);
    
    Thread Starter panhwerwaseem121

    (@panhwerwaseem121)

    Hello @ahmedkaludi, I found a solution for this issue, I’m not sure its perfect or not but its working perfectly fine for me, Solution: just add these 2 lines of code in your .htaccess file and it will resolve your issue.

    RewriteCond %{QUERY_STRING} ^(.*)&?_gl=[^&]+&?(.*)$ [NC]
    RewriteRule ^(.*)$ /$1?%1%2 [R=301,L,NE]

    I hope this will solve your problem.

Viewing 15 replies - 1 through 15 (of 19 total)