Viewing 15 replies - 1 through 15 (of 30 total)
  • Plugin Author Code96

    (@code96)

    Is your site using a framework, regular WordPress theme, or child theme?

    Plugin Author Code96

    (@code96)

    You will need to modify the plugin itself to get this to work.

    wp-content/plugins/php-mobile-redirect/includes/functions.php

    replace

    add_action('init', 'pmr_mobile_redirect');

    with

    function pmr_single_page_only(){
    
            if (is_page(42)){
    
                pmr_mobile_redirect();
    
            }
        }
    
        add_action('get_header','pmr_single_page_only');

    *note 42 in “if (is_page(42)){” should be changed to the ID of the page that you want the redirect to appear on.

    Keep in mind that when the plugin is updated, these modifications will be replaced and you will need to modify the code again.

    Thread Starter FaithJava

    (@faithjava)

    Thanks for your response, have apply the above code to the plugin but not detecting mobile device and also not redirecting. What do you think might be the issue?

    Thanks again

    Plugin Author Code96

    (@code96)

    Please post the entire code from the plugins functions.php

    Thread Starter FaithJava

    (@faithjava)

    okay I will do that right away

    Thread Starter FaithJava

    (@faithjava)

    <?php
    
    	add_action('init', 'pmr_mobile_redirect');
    
    	function pmr_mobile_redirect(){
    
    		global $pmr_options;
    
    		if ($pmr_options['enabled'] == true)
    		{
    			$detect = new Mobile_Detect();
    
    			if ($detect->isMobile() && isset($_COOKIE[$pmr_options['mobile_cookie']]))
    			{
    				$detect = "false";
    			}
    			elseif ($detect->isMobile())
    			{
    				header('Location: https://' . $pmr_options['mobile_url']);
    				exit;
    			}
    		}
    	}

    [Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    Plugin Author Code96

    (@code96)

    Where did you add the code, I posted above?

    Thread Starter FaithJava

    (@faithjava)

    Sorry about that, I sent wrong code.
    Here is the code below:

    <?php
    
    	// Replace----
    	/*add_action('init', 'pmr_mobile_redirect');*/
    
    	// with-----
    	function pmr_single_page_only(){
    		if (is_page(591)){
    			pmr_mobile_redirect();
    		}
    	}
    	add_action('get_header','pmr_single_page_only');
    
    	function pmr_mobile_redirect(){
    
    		global $pmr_options;
    
    		if ($pmr_options['enabled'] == true)
    		{
    			$detect = new Mobile_Detect();
    
    			if ($detect->isMobile() && isset($_COOKIE[$pmr_options['mobile_cookie']]))
    			{
    				$detect = "false";
    			}
    			elseif ($detect->isMobile())
    			{
    				header('Location: https://' . $pmr_options['mobile_url']);
    				exit;
    			}
    		}
    	}

    [Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    Plugin Author Code96

    (@code96)

    What is the URL to the page you are trying to redirect from?

    Thread Starter FaithJava

    (@faithjava)

    The example is like trying to access a page from URL https://www.mysite.com/movie/movie509
    and re-direct to https://www.mysite.com/mobiledevice

    Sorry about not given you my original URL,is just only for security reason, I hope you can understand.

    Thanks

    Plugin Author Code96

    (@code96)

    I understand. No worries. The only thing I can think is that you have entered the incorrect page ID. I have tested the code I gave you on several test sites, and it functioned correctly. How did you go about finding your page ID?

    Plugin Author Code96

    (@code96)

    There are also alternate methods to identify a single page, see below and give some of the other options a try:

    is_page();
    // When any single Page is being displayed.
    
    is_page(42);
    // When Page 42 (ID) is being displayed.
    
    is_page('Contact');
    // When the Page with a post_title of "Contact" is being displayed.
    
    is_page('about-me');
    // When the Page with a post_name (slug) of "about-me" is being displayed.
    
    is_page(array(42,'about-me','Contact'));
    // Returns true when the Pages displayed is either post ID 42, or post_name "about-me", or post_title "Contact".  Note: the array ability was added at Version 2.5.
    Thread Starter FaithJava

    (@faithjava)

    Thank you for your quick response, firstly I’m using a premium theme which is the default wordpress theme.
    How I got my page ID is I went on the edit post section of my wordpress admin, and click on “Get Shortlink” button, a dialog box with page URL display: https://www.mywebsite.com/movie/?p=591

    That is how I got my page ID = 591

    Meanwhile, I shall give those above option a try now

    Plugin Author Code96

    (@code96)

    Ok, so it sounds like you are actually trying to redirect from a post not a page? If so you need to replace:

    is_page(591)

    with

    is_single('591')

    Thread Starter FaithJava

    (@faithjava)

    Thank you, I shall get back to you soon

Viewing 15 replies - 1 through 15 (of 30 total)
  • The topic ‘Apply Redirect to a particular page only’ is closed to new replies.