Support » Themes and Templates » define a theme constant?

  • hello all,

    im working on a new theme right now, and plan to release more in the future.

    thing ive noticed is you have to right alot of functions and make sure there unique, so i generally call them:

    function themenamefunction
    function themenamefunction2


    is there a wauy i can setup a constant like this?

    $themename = 'name_of_theme";
    function $themename.function
    function $themename.function2


    i tried it a few ways but arent brilliant at php so could anyone point me in the right direction?

Viewing 7 replies - 1 through 7 (of 7 total)
  • I have variables set up at the beginning of functions.php like:

    $shortname               = "ve";
    $mytheme_template_dir     = get_bloginfo('template_directory');

    etc..whatev I need. I have like 8 files I use to put functions into….using these variables is easier to use/remember

    then I use $shortname, or the others all over the place… like in option arrays

    		'name' => __( 'Colour Scheme', 'voodoo_lion' ),
    		"desc" => __( 'Select the colour scheme for the theme', 'voodoo_lion' ),
    		"id" => $shortname."_color_scheme",
    		"type" => "select",
    		"options" => array( "","default", "reds"/*, "black", "purple"*/ ),
    		"std" => "reds"

    or functions

    function mytheme_css_and_scripts() {
    	global $mytheme_template_dir;

    thanks for the reply, but doesnt really help me.

    i too have a lot of different files linked with functions (shortcodes/help/widgets/general/optionspage/etc)

    i was hoping i could implement something similar to the $shortname for my entire functions files.

    right know i have a theme im working on called “press3”

    so my functions look like this

    function press_3_widget_load
    function press_3_register_sidebar


    when i want to create a new theme, i need to go through all of these files and change the press_3 part to whatever relates to the new theme.

    but if i could set something up like the shortname you mentioned, i would only have to change the original

    &themename =

    and all functions would work and be named specific to new theme.

    maybe if this isnt possible i could add in a str replace function right at the begining of the original functions.php file???

    I thought that’s what I was saying?

    I define $shortname as ve in my theme, right at the top of functions.php….. then I use $shortname all over the theme

    If I was to move a bunch of the functions and arrays to a new theme, all I would have to do is rename $shortname to something else and it would work just fine

    yes i know, but you use it within a function, not to name a function.

    function $shortname.setup(){

    the above code doesnt work.

    Ah, I see! Sorry, wasn’t reading totally straight

    Why do you need the functions renamed for each theme out of curiosity?

    Since only one theme can be active, the functions can’t conflict with each other….so they can always have the same name theme to theme….

    If just for naming sake…. instead of naming my functions after my theme, I name them after my company….

    Like my company is The Voodoo Empire, so all my functions are named voodoo_something

    I just use them like that throughout all my themes. Just not sure if there is a certain functionality you are after here?

    its not for specific use, its just a suggestion i got from a theme reviewer last time i submitted my theme.

    they said the functions should describe what they do (ie press_3_load_sidebar_1)

    i think i may go through and do as you suggested, name functions on a different basis.

    i may use your $shortname method for text domain/translation though.

    do i have to call “global” inside each function i call these?

    you call global to grab variables from outside the function

    here’s a decent article on global variables

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘define a theme constant?’ is closed to new replies.