1

I am a WordPress newby.

So far, it has been very easy to use WP to replace my self-made code used to manage users' login, write and output posts and static pages in 3 of my existing websites. I did it by installing WP in its own directory, by adding one exception to my .htaccess' mod_rewrite rules and by creating a blank vanilla theme. I have to and do include:

<?php require($_SERVER['DOCUMENT_ROOT'] . '/wp/wp-load.php'); ?>

in every page in order to have access to WP functions.

Everything works fine and better than it did with my outdated dirty solutions.

Now, I was hoping to leverage WP a bit more by customizing its admin-bar and replace the one I currently use. But I am not able to have the admin toolbar showing on my pages.

My test page looks like this:

<?php require($_SERVER['DOCUMENT_ROOT'] . '/wp/wp-load.php'); ?>
<html>
<head><?php wp_head(); ?></head>
<body>
<?php
  echo"<pre>";print_r($current_user);echo"</pre>";
  wp_footer();
?>
</body>
</html>

I know I can use WP funtions and login is successful because as I can display logged user info.

in functions.php I also have alternated, without luck, all permutations of:

add_filter( 'show_admin_bar', '__return_true' , 1000 );

and

show_admin_bar( true );

it shouldn't matter anyway because in my account setting page, "Show Toolbar when viewing site" is checked and I can see that in the table wp_usermeta, the key show_admin_bar_front is set to true.

also, if I use:

<?php require($_SERVER['DOCUMENT_ROOT'] . '/wp/wp-blog-header.php'); ?>

instead of

<?php require($_SERVER['DOCUMENT_ROOT'] . '/wp/wp-load.php'); ?>

I still don't get the admin toolbar, but my page return a 404 header.

I do not have any plug-in installed.

any help will be greatly appreciated.

thank you! M<

1

To answer your information from the comments (which actually should be edits to the question):

So far, it has been very easy to use WP to replace my self-made code used to manage users' login, write and output posts and static pages in 3 of my existing websites, without altering anything else the websites.

You wouldn't believe how easy it is to put some random code in WordPress context: Use a plugin, a theme or a mu-plugin (or if appropriate a Drop In). And you wouldn't believe how less work it is:

<?php /* Plugin Name: I AM DROPPING MY CODE HERE */
// Load your "out of WP context"-code here

is all you need. Really!

Just stuff your code in a folder, put it in the ~/wp-content/plugins/ folder in a subfolder named of your choice and put above code in the file that loads your routines. That's it.

I was hoping to leverage WP a bit more by customizing its admin-bar and replace the one I currently use.

Then use a (mu-)plugin. If you are now trying to build a DB connection and other stuff, then you will anyway simply load WordPress like WordPress loads itself. The thing you will end up is a not maintainable wrapper for WordPress, while WP delivers convenient wrappers already by itself in the form of (MU-)Plugins & Themes.

Hint: A theme isn't really much more effort than a plugin. Just add a folder to your themes folder (name of your choice) and two files: index.php and style.css. As soon as you add a Comment on top of your style.css file you have a theme that you can activate in the back end. The index.php will hold your code and be loaded on every request.

/* Theme Name: Twenty Thirteen */

I will look into plugins and how that could let me use my code in a standard WP installation. But as always I have little time, learning too much about WP is not the short term solution I am looking for.

You already invested quite some time to ask this question and try to work around WP. All the resources you will need to proceed further will be useless for you as long as you are out of context of WP. This is a simple calculation: 10 minutes to bring your code in context vs. whatever time you needed to ask this question, comment, etc. and all the pain you will suffer from any next task.

  • I really want to thank you for your patience. I updated my question and I give up on the admin bar for now; I believe it is not possible to have it with my set-up, for some reason. I will definitively work into changing my perspective and follow the direction you're pointing me to. I will leave this question open because I know is something others are struggling with as well. All the info on the topic I found around are collected in the question I believe. – Mikele Jan 26 '15 at 12:10
  • @Mikele n/p. If this answer works for you, please tick the "solution"-check mark below the voting arrows on the left of this answer. Thank you. – kaiser Jan 26 '15 at 12:11
  • absolutely! done. – Mikele Jan 26 '15 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.