A function is a sequence of program instructions that perform a specific task. It is packaged as a unit that can be used wherever the according task should be performed.

learn more… | top users | synonyms (2)

2
votes
2answers
3k views

Adding a second email address to a completed order in WooCommerce

Before I ask this question, I know there is a (legitimate) hesitation to answer questions here about Woo products since they have their own support and their users should be encouraged to use that. I ...
2
votes
3answers
15k views

How to set and use global variables? Or why not to use them at all

UPDATE: My original question has been solved, but this is turning into a valid discussion about why not to use global variables, so I am updating the question to reflect that. The solution was ...
2
votes
5answers
556 views

Allow users to add custom functions to wordpress theme

I'd like to allow users to add functions to the theme I'm developing, but don't want users to change functions.php directly, as this file may be updated with theme updates. In other words, I'd like ...
2
votes
3answers
1k views

the_post_thumbnail fallback using hooks

I am using this big theme that is almost entirely relying on widgets and sliders. Now I trying to avoid looking for post_thumbnail output code in all the included files in order to achieve fallback ...
2
votes
2answers
759 views

What is the most efficient method for loading widgets in functions.php

I have seen WordPress developers use two different methods for loading custom widgets from the functions.php file. The first: include("functions/my-custom-widget.php"); The second: ...
2
votes
2answers
2k views

How do I “unhook” / de-register jQuery so that it's not called as part of wp_footer();?

I need to "unhook" jQuery from my wp_footer() ... it's being called automatically and I'm looking for something I can add to functions.php which prevents it from being called a second time in the ...
2
votes
5answers
367 views

How to add another user to this remove_menu function?

Pretty self-explanatory. How does one add another user to this function for functions.php, i.e., user2, who will be shown different menu items than user1? I tried adding another ...
2
votes
1answer
2k views

Formating the_terms() function output

This code: <?php the_terms($post->ID, 'type') ?> Gives: <a href="/archives/type/image" rel="tag">Tag</a> What do to if I want to display only "Tag" word, not link eg. Tag ...
2
votes
2answers
662 views

Advantages and disadvantages of using automatic-feed-links

What are the advantages and disadvantages of using add_theme_support('automatic-feed-links') in my functions.php file?
2
votes
1answer
801 views

Multiple Content Block

I'm trying to create a custom post type and would like that post type to have two content blocks. So that in the loop I can ask for content-1 and content-2 separately. I can write the code just ...
2
votes
1answer
2k views

plugins_url vs plugin_dir_url

Im seeing WordPress plugins either use plugins_url or plugin_dir_url when creating constants to some of their folders. Is one better than the other? examples: define( 'MEMBERS_URI', trailingslashit( ...
2
votes
3answers
743 views

Pinterest Integration Using functions.php

I use a theme to build an portfolio. I´d like to add an pinterest "pin-it button" into the fuctions.php: Facebook, Google+ an Twitter were done, just the pinterest won´t work. Can´t found the the ...
2
votes
1answer
1k views

Problem using is_single() to enqueue script from functions.php

I'm having trouble only adding scripts to single post pages. I need to both include and exclude certain scripts using is_single() but it doesn't work either way I try it. I have the template tag on ...
2
votes
1answer
2k views

Proper use of Output Buffer

I'm attempting to use actions to override function calls I currently have throughout a template (to make updating certain replicated sections easier). For example, in archives.php I have the ...
2
votes
1answer
5k views

Custom page with variables in url. Nice url with add_rewrite_rule

Using WP3.1 I Have a custom page with a WP_Query and the query gets dynamic variables from the url. And i want safe variables and clean urls. Example: ...
2
votes
2answers
50 views

Advice: Template structure - php blocks in sidebar or someting else?

I'm trying to create certain modulair blocks which I can add to multiple pages in Wordpress. But I use sidebar-[name].php files for this, what is the best practice for this? Should you add them to a ...
2
votes
2answers
652 views

Auto close (hide) custom metabox / set default state

I am using the WordPress function add_meta_box() to add my own custom metabox. So how can I auto close/hide on page open ? Currently, I just add a CSS class closed to metabox's <div> element ...
2
votes
1answer
127 views

Does WordPress Development Mode Exist (with not minified JS)?

A lot of WP JS is minified and therefore it's hard to be analyzed in the Console. Is there any way to have all scripts uncompressed?
2
votes
1answer
780 views

wp_is_mobile function

Let me know whether wp_is_mobile function will work with all the mobile and tablet devices ? Is it enough to check mobile device ? I found that this method in wp-includes/vars.php function ...
2
votes
2answers
4k views

paginate_links() don't properly work in search.php?

I'm using this in my search.php template … <div class="pagination"> <?php echo get_pagination_links(); ?> </div> And this is the function … function get_pagination_links() { ...
2
votes
3answers
839 views

How to add .htaccess code through a function?

I need to add the following .htaccess code through a function <IfModule mod_deflate.c> # Insert filters AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/html ...
2
votes
2answers
2k views

delete uploaded file

I have a function wp_handle_upload() for uploads files. $file = $_FILES['attachment_icon-' . $i]; $upload = wp_handle_upload($file, array('test_form' => false)); what is a function for delete a ...
2
votes
1answer
2k views

Wordpress Enqueue for homepage only, functions.php, wp-framework

I'd like to replace my: if(is_home()) { wp_enqueue_script( 'homestuff', get_theme_part( THEME_JS . '/home.js' ), array( 'jquery' ), null, true ); wp_enqueue_script( ...
2
votes
2answers
295 views

Cleaner way to access custom fields in code?

I have 15 custom fields that I use to generate reviews for my site. Currently I access each field like this: //Buy or rent, type home, price if ( get_post_meta(get_the_ID(), ...
2
votes
1answer
1k views

jQuery plugin function is not a function

I'm having a problem I've never seen before. In a very new WordPress install, I uploaded a theme I had been working on for a friend's restaurant: CornerPocketPub.com The problem, as you can see, is ...
2
votes
3answers
369 views

How can I change the frequency of a scheduled event?

I have declared a scheduled event in a plugin like this : function shedule_email_alerts() { if ( !wp_next_scheduled( 'send_email_alerts_hook' ) ) { wp_schedule_event(time(), 'hourly', ...
2
votes
1answer
2k views

Custom function for user register in wp?

I have a custom template for user registration. I want to use a function to insert users. Can I directly call wp_insert_user() function?
2
votes
3answers
546 views

wp_enqueue_script + how to load JS or CSS in one URL merge call?

Is there any proper wordpress way of including the JS and CSS through one merged URL? So that instead of loading in x number of separate calls for each JS asset, it can be all merged into one URL? ...
2
votes
1answer
1k views

How do I display a tag cloud with both post tags AND a custom taxonomy?

Using wp_tag_cloud(), how can I display a single tag cloud that incorporates both regular post tags and a custom taxonomy?
2
votes
1answer
48 views

How do I know what variables are passed in a filter/action and what their meaning is?

Something I have seen several times now and I don't understand is the following: In a theme's functions.php a function is defined and then attached to a hook, like so (simplified example): function ...
2
votes
3answers
2k views

Add input field to 'Pages > Edit Page' through functions.php

Original Question: I'm trying to add an input field to 'Pages > Edit Page'. The use of this input field will be for a user to add an ID of a slider, so that that slider will be page specific. ...
2
votes
1answer
59 views

Why do filters/actions require an argument count?

I was just looking at plugin.php trying to answer the above question and I couldn't work it out. The actual code that calls filters is this: do { foreach( (array) current($wp_filter[$tag]) as ...
2
votes
2answers
335 views

Should I ask a theme developer to use locate_template rather than require_once

I was creating a child theme today and needed to overwrite a php file which was included using this code in the themes functions.php file require_once( get_template_directory() . ...
2
votes
1answer
2k views

Add container to nav_menu sub menu

Is there a way I can wrap a div around wp_nav_menu's ul.sub-menu So for example the markup would go from <ul class="menu"> <li><a href="/">Item 1</a></li> ...
2
votes
2answers
233 views

Attach a private function at a hook?

I have a class with some private & public functions. The thing is that I don't want some of the functions to be able to be called outsite of the class, so I want to make them private. But I need ...
2
votes
1answer
209 views

Nesting Functions within Functions

I'm looking for an efficient way to group a series of separate but related functions for a child theme I'm designing using theThematic Theme Framework. Thematic does a great job of providing plenty of ...
2
votes
2answers
1k views

How to register images uploaded via FTP in media library?

I'm using my own upload.php file to upload images to: $upload_dir = wp_upload_dir(); $targetDir = $upload_dir['path'].'/'; It works like it should with this exception that images uploaded to ...
2
votes
2answers
2k views

WP_Query in functions.php

I've got some code that I want to turn into a function. It works great until I wrap it in said function: $args = array( 'posts_per_page' => -1, 'post_type' => ...
2
votes
3answers
1k views

Functions.php code that only runs on localhost?

I would like to run an add_action in functions.php only if the theme is being loaded from my localhost development site. How would I get this to run only on localhost? function livereload(){ ?> ...
2
votes
1answer
2k views

why doesnt is_home() work in functions.php

I'm pulling in scripts.php through functions.php. this is in scripts.php but for some reason, wordpress isn't recognizing is_home(). i've tried resetting the query, but to no avail. Am I hooking into ...
2
votes
1answer
1k views

add_action in a function, is it possible?

I am trying to add some js to the head using add_action('wp_head', 'js_func'); which works when posted just after the function, however I do not want it posted on every page, just the page that it's ...
2
votes
5answers
493 views

Remove Comments Metabox but still allow comments

I already know how to remove a metabox from my custom post type edit page. However I want to remove the comments metabox but still allow commenting for the post. Because I notice when I do remove ...
2
votes
2answers
963 views

wordpress custom login successful redirect hook

I am using a custom login form imported on my theme's home page through jqModal. In that, when i successfully login it redirects to the same page. I want to redirect based on the logged in user role. ...
2
votes
2answers
3k views

Wordpress 3.1 - How does one add sticky post capabilities to post types

In wordpress 3.1 they finally added the option of allowing posts belonging to a custom post type to be marked as "sticky"... what I can't figure out though is how to enable this so the admin menu ...
2
votes
4answers
4k views

Remove_filter ('the_content', 'wpautop') is not working

I've tried disabling WP's auto-paragraph thingy using remove_filter ('the_content', 'wpautop'); but I am still getting my stuff wrapped in automatic <p> tags... What am I doing wrong? Its at ...
2
votes
3answers
439 views

Link Category Description

I'm pulling my hair out over this. In the Links manager, you can enter a description for the category (in addition to the link itself). However, in wp_list_bookmarks, there is no way to call this ...
2
votes
1answer
200 views

Add description text under input field for new profile fields

How can I modify my following code to add some description text under the input fields? I tried modifying it as you can see with the facebook url field but the text shows up under the field label and ...
2
votes
2answers
145 views

Setting featured image with function, 1 part not working

I'm trying to set a post's featured image based on custom fields. There are different types of posts and therefore the featured image should be set depending on which custom fields have been filled ...
2
votes
1answer
257 views

WP doesn't show Array Custom Fields?

I'm wondering why WordPress doesn't list PHP array() and any serialized data in Custom Fields in Admin Panel (for Pages, Posts etc.)? Only Custom Fields containing strings and numbers show up and can ...
2
votes
1answer
2k views

How to manually activate user in dashboard only by admin

I'm looking for a function that allows admins (only) to activate new users. When a user registers he have to be approved by the admin before he gets access to log in. Does anyone know how I can do ...