0

This issue has been driving me up a wall.

I've been working on a mobile website for a friend who uses wordpress. I'm attempting to modify a wordpress plugin that "rethemes" each page for mobile users. I want the plugin to do it's normal thing ("retheme" the page) iff the user is on the blog page, otherwise (if the user visits a different page, he will be redirected to a different address (the address of the mobile website).

In order to do this, I have to be able to detect whether I'm on the blog page, or a different page when the functions in the plugin are run.

I tried condtionals like is_home, is_page(id), ect., but none of them work. I also tried parsing the url and attempting to determine the page that way, but I can't.

I'm just getting my feet wet with PHP, so I'm really not sure what to try next.

To restate my question: How can I determine whether I'm on a certain page within a wordpress plugin function?

The plugin, for the record, is "Wordpress PDA & iPhoned" (http://imthi.com/wp-pda/)

Here's the relevant code:

function PDAPlugin() {
        if(true) {
        header("Location: http://adavidcreation.com/mobile");
        exit;
        }
...
}

This works, but I want to change the if statement to only be true if it's NOT the blog.

Any help would be greatly appreciated!

ihake
  • 1,741
  • 1
  • 17
  • 29
  • 2
    If the function is being called outside the php file for the page, the conditionals like is_home, is_page, is_archive will not work and neither will parsing the URL, because it is not run on the page. You need to put that function on the page where you want to run it, like archive.php. If you just want the re-direct functionality, you can take that piece of code you have pasted here and put it on the top of header.php and you can check to see if the page is the blog page there. The plugin will still generate the mobile site for you, but the redirection code will need to go in the header file. – anuragbh May 16 '12 at 09:43

1 Answers1

0

Try using this, which should retrieve the page id: $id = get_option('page_for_posts');

If this doesnt work -> https://wordpress.stackexchange.com/

Community
  • 1
  • 1
Joelmob
  • 1,076
  • 2
  • 10
  • 22