• Hi, I created theme options to insert a page title into a function but can’t seem to get it to work… if I manually enter the page title into the is_page it works though. Here’s my code-

    function emr_single_page_only(){
    		if (is_page($emr_options['pagetitle_url'])) {

    Thanks in advance for any suggestions ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • Is $emr_options a global variable or defined somewhere else? If not then that’s the problem, at that point $emr_options doesn’t equal anything.

    The first thing I do when testing variables is to check if it even has anything. You can do this by adding the following line just above the if statement:
    echo '<pre>', print_r($emr_options), '</pre>';

    If you don’t see anything then the variable is not set. Otherwise you’ll see a list of values contained in $emr_options, including ‘pagetitle_url’ if it’s there.

    Can you try: is_page(get_option('pagetitle_url')) instead?

    Thread Starter uniquelylost

    (@uniquelylost)

    Thanks for the help @oz

    Okay so I can get the first pagetitle_url to work but if I try to add additional ones like pagetitle_url22 they don’t work… I can confirm that the values are getting saved in the db… here’s an example of my code-

    function emr_single_page_only(){
    		global $emr_options;
    		if (is_page(get_option('pagetitle_url'))) {
    			emr_mobile_redirect();
    		}
    		elseif (is_page(get_option('pagetitle_url22'))) {
    			emr_mobile_redirect2();
    		}
    	}
    	add_action('get_header','emr_single_page_only');
    
    function emr_mobile_redirect(){
    		global $emr_options;
    		if ($emr_options['enabled'] == true)
    		{
    			$detect = new Mobile_Detect();
    			if ($detect->isTablet() && $emr_options['tablet'] == true)
    			{
    				$detect = "false";
    			}
    			elseif ($detect->isMobile())
    			{
    				header('Location: ' . $emr_options['mobile_url']);
    				exit;
    			}
    		}
    	}

    Again, thanks in advance for any suggestions.

    Thread Starter uniquelylost

    (@uniquelylost)

    After much trial and error I wonder is it even possible to use multiple is_page in this manner? If so it seems my logic is off for the ‘function emr_single_page_only()’.

    Moderator bcworkz

    (@bcworkz)

    is_page() can be called as often as needed, that’s not the problem. Unfortunately, I’ve no idea what the problem may be, everything seems in order.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘is_page theme options not working’ is closed to new replies.