69690

how to hide a page from being seen in wordpress backend and frontend

Question:

In my plugin i have created a custom template that prints a requested sidebar. and for running the code of this template i assigned a custom page to it (by calling update_metadata) .<br /> Is it a good idea for getting content of a specific sidebar into Ajax call ?<br /> Now my problem is that WORDPRESS shows it in the dashboard and front page , and after searching i have not found any easy to understand solution for Hiding a page completely so only can be accessed by its id .<br /> Can any one tell me how to do that ?

Answer1:

you are going about this the wrong way. You can create a function that can create anything that can be created on a wordpress page.

But if you really must you can create a page outside of the database, etc:

add_action('init', 'add_rewrite_rule'); function add_rewrite_rule(){ // add_rewrite_rule(REGEX url, location, priority (i.e. top is before other rewrite rules) // I created a custom post type for this plugin called market -- replace post_type with whatever you want //basically tell wordress to add a query var if sidebar is added to url. add_rewrite_rule('^sidebar?','index.php?is_sidebar_page=1&post_type=market','top'); } // register a query var add_action('query_vars','market_set_query_var'); function market_set_query_var($vars) { array_push($vars, 'is_sidebar_page'); return $vars; } // associate a template with your quer_var add_filter('template_include', 'market_include_template', 1000, 1); function market_include_template($template){ if(get_query_var('is_sidebar_page')){ $new_template = (theme or plugin path).'/pages/yourpage.php'; // change this path to your file if(file_exists($new_template)) $template = $new_template; } return $template; }

This will not be a page that will be in the admin section or in any query that relates to pages but someone could of course navigate to this page. But as i said above you would be better to create a function to create your sidebar. If you want a seperate file to handle the "view" you use require_once 'filename'; a file and keep your functions area free of html.

If you are creating functions in a wordpress plugin dont forget many functions may not be available until later in the load process. Use add_action() if you run into any undefined functions

edit:

you are loading wordpress before you get to the template so you have all the functions. (google wp load for more info) + get_header() / get_footer() will also load a few things like css, etc. I had a small typo in the code above, fixed that but basically what you are doing is telling wordpress if someone lands on www.example.com/sidebar to apply a query_var (rewrite rule). Wordpress will look up its saved vars (final function) and return the template assoc. The 2nd function just registers the var.

You also have wp_functions in any file you create and include in a plugin, etc hence why you can create a file that does exactly the same as this page.

Recommend

  • iOS/Swift: in which function between viewDidLoad and viewWillAppear am I supposed to query a databas
  • Why java statement evaluation is happening like these ?
  • htaccess will not rewrite subdomains
  • Wordpress and Drupal SSO/Single Sign On
  • wordpress query - next two events by metadata date
  • How does Skobbler prioritize which POIs to show?
  • IIS 7.5 404 Error for .PDF files
  • Log4j cannot find properties file in a simple application
  • Refactoring advice: maps to POJOs
  • Regex for URL rewrite with optional query string parameters
  • How to validate a year I enter in textbox using jquery rule?
  • Laravel at least one field is required
  • Efficient User-Agent Regex to find Safari in Python
  • Is there some graphical way to create my own configuration file on SonarLint?
  • Zoom in and out of jPanel
  • Apache RewriteRule redirection with url encoded
  • Firefox Extension - Monitor refresh and change of tab
  • Saving Changes After In-App Purchase Has Been Purchased
  • htaccess add www if not subdomain, if subdomain remove www
  • Use of this Javascript
  • Extracting HTML between tags
  • Change multiple background-images with jQuery
  • Algorithm for a smudge tool?
  • MongoDB in PHP using aggregate to group by _id is null not working
  • Regex thinks I'm nesting, but I'm not
  • Can Jackson SerializationFeature be overridden per field or class?
  • To display the title for the current loaction in map in iphone
  • Circular dependency while pushing http interceptor
  • Android Studio and gradle
  • AngularJs get employee from factory
  • Free memory of cv::Mat loaded using FileStorage API
  • How to set the response of a form post action to a iframe source?
  • Memory offsets in inline assembly
  • Change div Background jquery
  • Turn off referential integrity in Derby? is it possible?
  • Reading document lines to the user (python)
  • Binding checkboxes to object values in AngularJs
  • Net Present Value in Excel for Grouped Recurring CF
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?