WordPress.org

Ready to get started?Download WordPress

Forums

Custom Theme Options (7 posts)

  1. grs
    Member
    Posted 4 years ago #

    I created a wordpress theme and added a theme options page using this tutorial.

    I have a small issue and I think it might relate to the wp_enqueue_script wp_enqueue_style section of the code.

    I have my theme set up locally on two computers using xampp, one at home and one at work. The theme options section works beautifully at work but the js and css is not called on my set up at home. The theme files are identical (I have checked and rewritten repeatedly) but I can not get the options page to work properly at home.

    Can anyone help me out with this? Is it an enqueue script issue or something else? I am pulling my hair out trying to figure out what is wrong.

  2. Mark / t31os
    Moderator
    Posted 4 years ago #

    The code in that tutorial is using loads of deprecated functions i'd suggest finding a better and more upto date article and code to work from, i cannot honestly recommend following that guide, far too outdated (and there's silly coding errors in there i can't ignore).

    I'd suggest using the following instead (better written code and not using old functions).
    http://themeshaper.com/sample-theme-options/

    In regard to the enqueue problem, the first thing to do would be confirm if the script or style is output into the source of the page.. (view source).

    If they're not appearing in the source of the page, then the problem must be with how you're enqueuing them, in which case i'd ask if i can see the code you're using to enqueue and where you are placing the enqueues.... Please .. :)

  3. grs
    Member
    Posted 3 years ago #

    Thanks for your fast reply, apolgies I could not match your speed, its been a busy week.
    Well after your critique of that tutorial I am inclined to redo my theme options page. I am still quite a novice when it comes to php so I'm not sure if the link you posted will give me the spoon feeding I need. I will give it a go regardless.
    I would still like to know where I am going wrong with my current theme options though. Like I said I am a novice, so I've grabbed bits from here and there and mashed them together. If you can tell me why this works on one computer and not the other I would greatly appreciate it.

    [code moderated] Code should be provided by way of a pastebin for anything over 15-20 lines. Have made the necessary paste for you this time.. ;)
    http://wordpress.pastebin.com/uhPP5Kb7

  4. Mark / t31os
    Moderator
    Posted 3 years ago #

    Hi,

    As i said before in regard to the enqueue problems, check the source and confirm if the styles/scripts are being printed into the source/output of the page correctly first.

    However, i don't think i've seen enqueues hooked onto init before, so that could be the problem. There are hooks available specifically for enqueuing scripts, namingly admin_print_scripts or admin_head (assuming you're targetting the administration pages).

    Hope that helps...

  5. grs
    Member
    Posted 3 years ago #

    Sorry I forgot to mention that they were being printed. Thanks for your help, I will do a bit more research with the hooks you have suggested.

  6. grs
    Member
    Posted 3 years ago #

    I started again using the themeshaper article, I have hit a snag. I want to change the drop down so that it displays all the pages. This is what I have used

    $pages = get_pages();
    foreach ($pages as $pagg) {
    	$select_options[$pagg->post_id]["value"] = $pagg->post_id;
    	$select_options[$pagg->post_id]["label"] = $pagg->post_title;
    }

    however this only displays the most recently created page.
    How do I get it to show all created pages?

  7. Mark / t31os
    Moderator
    Posted 3 years ago #

    Your foreach loop is setting the same array item with each iteration instead of creating additional ones, try this instead..

    $pages = get_pages();
    foreach ($pages as $pagg) {
    	$select_options[] = array(
    		'value' => $pagg->post_id,
    		'label' => $pagg->post_title
    	);
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.