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)

11
votes
3answers
1k views

Where do I put the code snippets I found here or somewhere else on the web?

Many posts here or somewhere else contain code, but they do not say where to put it. Example: I have found this post: How do I turn off 301 redirecting posts (not canonical)? I'm a newbie with PHP. ...
207
votes
108answers
88k views

Best Collection of Code for your functions.php file [closed]

Please vote on the question and any answers you find useful by clicking on the UP arrow on the left hand side of the question or answer. As with many others who are now viewing this post, I have been ...
9
votes
3answers
13k views

How to manually fix the WordPress gallery code using PHP in functions.php?

It's been talked many times that Wordpress outputs some really bad code for the built-in gallery function. This is the core code responsible for the gallery output (in /wp-includes/media.php): ...
1
vote
2answers
3k 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
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 ...
0
votes
1answer
4k 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: ...
3
votes
1answer
411 views

Check if post is being published for the first time, or is an already published post being updated

I am building an add-on to an events module that checks for availability, since there wasn't a function for that in that module. Now that I have built the logic, there are three emails I will need to ...
17
votes
2answers
5k views

Between functions.php, widgets and plugins, which is loaded first?

Customer asks if a specific carousel plugin he uses can be widgetized. That means i should create a widget inside functions.php which calls the plugin's function. That means that the plugin's code has ...
12
votes
1answer
6k views

How to override parent functions in child themes?

I've been reading around and trying to figure out how to do this, but for some reason I can't seem to override parent functions in my child theme. I'm using TwentyTen as a parent - can anyone tell me ...
5
votes
2answers
610 views

Use AJAX in shortcode

I have the following code to the shortcode to display a random quote. Question: how to make a button display a new random quote? I mean, that would hit the button and show you a new quote (without ...
1
vote
2answers
224 views

How to activate “Description” metabox for menu item programmatically?

I'm creating custom wordpress theme. How can I enable "Description" metabox for menu items (on nav-menu page) by default programmatically?
1
vote
2answers
2k views

class=“parent” for wp_list_pages?

<div class="menu"> <ul> <?php wp_list_pages('exclude=&title_li='); ?> </ul> </div> creates the following output... <div class="menu"> ...
1
vote
1answer
56 views

disable comments if array exists

This is the code which is registering the function for rewrite_endpoints(): function wpa121567_rewrite_endpoints(){ add_rewrite_endpoint( 'comments', EP_PERMALINK ); add_rewrite_endpoint( 'stats', ...
1
vote
2answers
929 views

Is it possible to disable a function of a parent theme?

I was wondering whether it is possible to completely disable a function that is called in a parent theme's functions.php and if so, how? (Of course without deleting the function. Rather by adding ...
0
votes
1answer
101 views

How to redirect users to custom lostpassword page?

How to redirect users to custom lostpassword page when they click on the Error: Lost your password?. Because I set a redirect for wp-login.php to my custom login page. when a user click on Error: Lost ...
0
votes
3answers
133 views

My function doesn't work into WordPress but outside, it works - what am I missing?

I used a functions into my page I created for WordPress, it's working, but the functions 're not working, doesn't showing any result. For example: <?php function tester() { global $pol; $pol="ok ...
11
votes
4answers
8k views

What's the difference between home_url() and site_url()

My understanding is that site_url() returns the location where the wordpress core files are. So, if my blog is hosted at http://example.com/blog then site_url() returns http://example.com/blog But ...
6
votes
2answers
2k views

How to add a custom metabox to the Menu Management admin screen?

Although I am very thankful to the wordpress core team that they have finally integrated native menu management capabilities I get frustrated with some key elements which I would like to change. I ...
11
votes
6answers
23k views

How to include PHP files in plugins the correct way

My problem is when on the main plugin file i include a php file something like this: include(WP_PLUGIN_URL . '/wordpress-group-buying/ipn/paypal-ipn.php'); //or include_once(WP_PLUGIN_URL . ...
3
votes
2answers
780 views

Modify CSS via Theme Control Panel

Hi to all I'm trying to create an advanced control panel for my first Wordpress template but I'm not able to add a function that I will need. The function that I'm trying to add is the possibility to ...
3
votes
3answers
3k views

Add new “Insert Into Post” button with another function

Problem: Add a hook that automatically adds a short tag to video attachments when inserted from the Media Library (video) tab: Update: This works under the 'Media Library' tab — and doesn't break ...
0
votes
5answers
4k views

How to style current page number (wp_link_pages)?

When a post is split on more pages TwentyTen theme use the native function wp_link_pages to display a navigation page bar at the end of post. I am trying to style those elements for my theme, but ...
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 ...
1
vote
4answers
7k views

How can you check if you are in a particular page in the WP Admin section? For example how can I check if I am in the Users > Your Profile page?

I'm building a plugin and I want to add bits of javascript in the admin head but only for certain admin pages. I don't mean pages as in a WordPress page that you create yourself but rather existing ...
0
votes
2answers
175 views

Override parent theme function that is not hooked or in the functions.php file

I need to remove a function from the parent theme and replace it within the child theme. The function is called print_meta($meta_box). The function is not pluggable and it located in a random file, ...
16
votes
3answers
20k views

Changing Admin Menu Labels

I have spent the last day using the functions.php file to fully customize WordPress for my client sites. I am amazed at how much I have been able to accomplish and how much easier it will make things ...
6
votes
2answers
3k views

How to change default position of WP meta boxes?

Im wondering if there is a way to change the default position of Wordpresses meta boxes such as "featured image" for custom post types without having to drag them manually? Example:
4
votes
2answers
820 views

Set JPEG compression for specific custom image sizes

I use various custom image sizes (by add_image_size) and I have set my JPEG compression to 30% with this filter: function jpeg_quality_callback($arg) { return (int)30; } add_filter('jpeg_quality', ...
7
votes
1answer
140 views

Shared functionality in plugins and themes

I recently started to develop plugins and themes and I found that I need to use several functions of on both. Sometime I think about to check if function / class exist before declared as said on this ...
7
votes
1answer
3k views

Redeclare/Change Slug of a Plugin's Custom Post Type

Is it possible to redeclare/change the slug of a plugin's existing custom post type (without simply editing the plugin)? That is, if Plugin X creates a custom post type with the slug /uncookedtoast/, ...
4
votes
2answers
691 views

Prevent publishing the post before setting a featured image?

As the title says , I want a plugin/function to prevent/inform the user when he tries to publish the post without setting the featured image. ANY HELP ???
4
votes
2answers
1k views

How to use a custom post type archive as front page?

I'd like to use a custom post type archive as a site's front page, so that http://the_site.com/ is a custom post type archive displayed according to my archive-{post-type}.php file. Ideally I ...
3
votes
1answer
1k views

Is it possible to use a forgot password url filter?

i recently found that a login url filter is available but i can't find a solution for the forgot password as well, for the login url i use this: function custom_login_url($login_url) { return ...
2
votes
1answer
603 views

Apply custom role capabilities to administrator (without plugin)

I have a custom role that allows access to only a sigle custom post type. This is all well and good, but now it is only showing up for this role, not for admin and super admin. I'm having a hard time ...
1
vote
1answer
545 views

Set posts of a custom post type to be private by default?

Say I created a custom post type called 'Private Posts' ($post_type = itsme_private_posts) and want all posts under the custom post type to be set to 'Private' automatically when published i.e. by ...
1
vote
1answer
572 views

Enqueue Javascript Correctly for 3.5

I am trying to create tabs for admin settings page in wp, but I think I'm doing it wrong. The example below shows how I did it but I don't know how to change this to use it correctly with no conflict ...
-1
votes
1answer
271 views

Integrating custom API for post content into Admin interface & Public Website [closed]

EDITED question to be more specific and added bounty in hopes someone has a solid coded solution: So, here is an interesting task I have been trying to find a solution for. I have added a bounty ...
6
votes
2answers
142 views

Memorizing syntax

I hope the following question is acceptable here. I rely entirely on copy/paste for most WP functions, however I guess WP veterans don't. Is it important to know by heart the common WP syntax, and if ...
4
votes
1answer
474 views

Can I turn off write-in tags/taxonomies?

One of the big problems my site staff has had with tags is the overwhelming number of similar or duplicate tags, due to the write-in ability. I'm about to add new custom taxonomies to my site for ...
2
votes
3answers
332 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', ...
0
votes
1answer
2k views

How to save Uploaded image in custom option panel?

I'm trying to add a custom option panel to a new template following a tutorial found on NetTuts. I saved all the code for the option panel inside a file called optionpanel.php (LoL) and everything is ...
3
votes
2answers
532 views

Default content for a post in one category?

This is a common function that adds default text to all posts: add_filter( 'default_content', 'my_editor_content' ); function my_editor_content( $content ) { $content = "default content goes ...
2
votes
1answer
642 views

Can I pass two roles to the function get_users?

I want to get the users of role academic and student. I have tried using the code below (passing an array of roles, but all users are being displayed, so clearly it's not working. ...
2
votes
2answers
1k views

Get password when user registers and save it sha1 into database

im working on a website where the users can connect with iphone to some functions of it by using a sha1 encrypted password. In other words the plain password of wordpress encrypted in sha1. In the ...
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 ...
1
vote
1answer
480 views

How to Removing fields from the Media Uploader/Gallery on a Custom Post Type Edit Page

This post shows how to remove unwanted fields from the media uploader. It works great, but I want to limit it to a custom-post-type and I can't seem to figure out how to do it. I've tried the ...
1
vote
1answer
183 views

Change comments form title on a page by page basis

I'm looking to change the comments form title (my theme defaults this to "Leave a Comment" or "Leave a reply to"). I thought perhaps I could add a hook to comment_form_defaults but my snippet below ...
0
votes
3answers
551 views

How can I show my latest tweet in my wordpress blog?

How can I show my latest tweet in my wordpress blog? in functions.php not use any plugin
-1
votes
1answer
121 views

get_footer can't find any variables set in functions.php

footer.php can't find any variables I set in functions.php, I've tried a global (urggh) and object array like so: $foo = (object)array("bar" => "test text"); It works within page template, just ...
-2
votes
1answer
327 views

How can I json_encode the output of my function?

How can I json_encode the output of this function I use to get all attached images of a post? <?php function get_all_images($postid=0, $size='bigger', $attributes='') { if ($postid<1) ...