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.
168
votes
108answers
59k 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 ...
14
votes
3answers
13k 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 ...
12
votes
4answers
208 views
How long does a deprecated function live in core?
I'm curious to find out the process/philosophy behind removing deprecated functions from core.
The Codex says this:
These functions below have been deprecated. That means they have been replaced ...
11
votes
2answers
555 views
How to make a image-size selected by default in Media upload - WP v3.5
Bare with me. I want to have a custom image size selected by default in the Media upload popup page. In Wordpress v3.4.2 and prior, this elegant code worked fine:
function ...
10
votes
1answer
4k 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 ...
9
votes
1answer
399 views
Is there a is_user_logged_in() for multisite?
Is there a is_user_logged_in() function for Wordpress MU / Multisite (3.0+) where I can add in the network site ID like is_user_logged_in(2) where 2 would be the site_id?
Update:
After a little ...
8
votes
2answers
3k 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 ...
8
votes
3answers
170 views
How to change the case of all post titles to “Title Case”
I am helping my father with his WordPress website.
It has over 1,700 posts with TITLES IN UPPERCASE.
We'd like to change these to "Title Case" in the database (possibly using this PHP script).
The ...
7
votes
6answers
12k 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 . ...
7
votes
2answers
181 views
Get rid of Wordpress category, tag and author archives?
I have searched the net with no success on what should be an easy thing.
I have a highly customized blog with pages, sub pages and posts. While I rely heavily on the use of categories and tags I ...
7
votes
4answers
4k 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 ...
7
votes
1answer
115 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
904 views
Using classes instead of global functions in functions.php
In many themes I've seen (including TwentyEleven) and in the examples I've found online, when building the functions.php file for a theme all functionality is declared in a global scope. To clarify, ...
7
votes
1answer
1k 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/, ...
6
votes
2answers
116 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 ...
6
votes
2answers
7k 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):
...
6
votes
3answers
301 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. ...
6
votes
5answers
7k views
remove empty paragraphs from the_content?
Hey guys,
I simply want to prevent the creation of empty paragraphs in my wordpress post. That happens quite often when trying to manually space content.
I don't know why this doesn't take effect?
...
6
votes
1answer
805 views
Set media upload attachment link to none and hide it in WP v3.5
In the Media upload popup page, how do I set the attachment link to none and hide it in Wordpress version 3.5? The following filter worked fine in earlier versions of WP:
function ...
6
votes
2answers
1k 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 ...
6
votes
2answers
711 views
Extract image from content and set it as the featured image
The problem:
I'm posting from the Wordpress iPhone app. When adding an image, the image shows up in the description itself, which I don't like.
What I'm trying to do:
Remove the image from the ...
6
votes
3answers
501 views
Order posts (across the whole site) by metadata date
My custom 'Home' page is set to sort my custom posts via the custom date field with this (updated to be custom named) code in functions.php:
// sort order for home page
add_action('wp', ...
5
votes
2answers
810 views
Change admin bar to default:off
While I quite like the admin bar I actually want it to be OFF by default instead of ON ( I don't want to disable it altogether because I want users to be able to turn it on if they want - but but I ...
5
votes
4answers
2k views
How to load parent_theme functions.php before child_theme?
I got the problem that i have to load my parent theme's functions.php file before my child theme's functions.php file loads. This is needed for the setup & init procedure. I looked at the hooks ...
5
votes
2answers
794 views
Remove “Insert from URL” link in Media upload - WP 3.5
How do I remove the Insert from URL link in the new Wordpress 3.5 Add Media popup page? In earlier versions of Wordpress, this worked fine:
// removes URL tab in image upload for post
function ...
5
votes
1answer
638 views
What is the difference between wp_register_sidebar_widget and register_widget?
What's the difference between them and when should we use each one ?
I'm using wp_register_sidebar_widget right now and it's working fine but I've seen a lot of tutorials online on how to create a ...
5
votes
1answer
366 views
Modify Admin Bar Link
Starting on line 474 of /wp-includes/admin-bar.php there is a function that is declared as the following:
function wp_admin_bar_new_content_menu( $wp_admin_bar )
What it does it generates the + New ...
5
votes
2answers
1k views
Passing arguments to a admin menu page callback?
Situation: I'm working on a plugin and I'm developing it as a class, everything worked fine until I run into this situation. I wanted to make things a bit cleaner and tried this..
class MyPlugin {
...
5
votes
2answers
112 views
How do I use the WP image functions in a page template?
Wordpress has tons of mature code for image editing on the admin side, but I would like to provide a form inside of a custom page template for my visitors to drag and drop, crop and save a thumbnail ...
5
votes
1answer
127 views
Gettext details
I've got a few gettext() questions that are not covered anywhere in WordPress Codex but I think they are important.
__('string') in THEME should be used for strings that are likely to be present ...
5
votes
2answers
965 views
How can I get $id variable in widget's form function?
How can I get $id variable in widget's form function?
According to widget's structure I see that widget function have $args as a parameter, which will be extracted in function's body. In my case i ...
4
votes
4answers
163 views
One Child Functions.php for Multiple Child Themes
I have a wordpress setup that I use for clients with around 30 or so child themes that they can choose from. Each child theme has it's own functions.php file currently. Is it possible to setup just ...
4
votes
4answers
232 views
Import Wordpress XML File from Within Functions.php
I am developing a theme which has a different method of adding in content and so, the default install of Wordpress won't show any content because of this. I was wondering if it is possible to ...
4
votes
3answers
595 views
clients list using wordpress
I am using wordpress for my new website and i have list of clients(name and their logos). I am confused how to make those editable using wordpress? Html as follows...
<ul>
<li><img ...
4
votes
7answers
2k views
Include files in child theme functions file
Typically in my theme function file I'll require other files to keep things neat.
require_once("foo.php");
Now working in a child theme I'd like to do that same. I'm adding custom admin options and ...
4
votes
2answers
257 views
Shared functions.php across multiple WordPress websites
I find myself using many of the same snippets of code for my functions.php file in new websites.
Is there a method I can use to create a few different shared functions.php files to use across my ...
4
votes
2answers
2k 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
1answer
75 views
function_exists call in function.php
In the function.php file of the twentyeleven the setup function checks to see whether it exists before running it:
if (!function_exists('twentyelevent_setup')):
function twentyelevent_setup() {
... ...
4
votes
1answer
379 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 ...
4
votes
1answer
85 views
Remove a menu item created by a plugin
I'm trying to remove a menu item and tried several approaches, but have not had any luck. It was created from a FAQ plugin.
If I use this line:
remove_menu_page( 'edit.php?post_type=question' );
...
4
votes
2answers
2k views
Enabling Sessions in WordPress 3.0
Im using a wfcart in my WordPress site but for some reason on certain pages WordPress drops the session I'm wondering if there is a way to enable sessions in WordPress 3?
4
votes
3answers
1k views
Removing Metabox for “Slug” without removing functionality
Here is an interesting question.
I have recently noticed that if you utilize the code
remove_meta_box('slugdiv', 'post', 'normal');
you are actually unable to modify the slug when you click on ...
4
votes
2answers
84 views
Notify users whenever a new post is published based on their preference
I have put together a custom registration form on my WordPress site and one of the items on the registration form is an ability to select an interest.
Essentially I have the following code from the ...
4
votes
2answers
130 views
current_cat_ancestor Alternatives
It looks like adding current-cat-ancestor class to category list was proposed, but never implemented. The only way I've been able to find so far is to re-create the wp_list_categories() function ...
4
votes
1answer
499 views
how to group custom post types
hi wanted to know do i group my custom post types to appear together in a group in the wordpress back end menu bar like this below in the picture what code do i have to use in my functions.php so that ...
4
votes
1answer
79 views
Programatically add options to “add new” custom field dropdown
How can I add pre-defined options to the "add new" custom field dropdown?
Here's two examples of automatically adding and showing new custom fields:
WordPress: Adding Default Custom Fields on New ...
4
votes
2answers
402 views
Build a content and excerpt grid loop with paging and options for # of posts
What I'd like to do: on index.php, a loop that shows a selectable number of full posts using the_content and then below that shows a selectable number (the number of posts can be hardcoded in the ...
4
votes
1answer
69 views
Hide Twenty Eleven Theme From Themes Page
Is there a way to hide the Twenty Eleven theme from the "Themes" page in wordpress? I have 10 themes for clients to choose from and i don't want them to be able to see the Twenty Eleven theme or be ...
4
votes
1answer
992 views
wp_get_attachment_image returns different image size
It is a bug?
wp_get_attachment_image( $attachment_id, 'post-thumb-size-small');
Same code, called in template, and in AJAX call returns same image SRC, but different image width and height.
dumb ...
4
votes
1answer
528 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 ???
