wordpress - How to get the current project name in php code?

689

I'm new to php. I want to use function get project name but i don't know how. Example:

F:\VertrigoServ\www\first_wordpress...

project name is "first_wordpress".

Pleas help me.

Thanks! Sorry for my english.

775

Answer

Solution:

This is hard to get because of some reasons:

  • Project name may change
  • Path may be different in your local system or in your web server, so you cant substring your path

What I suggest is to have a config file with some values that are constant in your project and that are going to stay always the same, like your project name.

I would create this:

constants.php

<?php

const PROJECT_NAME = 'first_wordpress';
const SOME_OTHER_CONST = 'whatever';
const FOO = 'bar';

?>

and then include it in the file you need it, for example

index.php

include 'constants.php';
echo 'This is my project name '.PROJECT_NAME;

I guess that you are using Wordpress, so your constant file, or config, is called wp-config.php. Try that!

Edit: a user of php.net brings this solution.

I hope it helps!

People are also looking for solutions to the problem: php - Remove all numeric index to have an assoc array only

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.