INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
Instant install of wordpress I just think about that... maybe it exist...you will tell me... Wordpressis a beautifull software, and the thing i like the most, is the instant install of the theme and plugin... So i though, why not have a onefile.html upload, and install wordpress ITSELF utomaticly fron the svn instead of having to upload a whole buch of file that take a looong time, and sometime failed... Maybe that file, will just select the language and the name of the folder... Or maybe, it exist ?... I know that the database must be done before... i do it, it's just the folder with 1000 files that weight 10 mg that bug me... autoinstall as plugin !
**Update: You can use WordPress QI -< Not all servers can run SVN, and servers which have problem in WP 5minute install, can't be cope up with another solution because there is no solution, sometimes server settings are to blame. That said, on a server where everything works fine for a regular installation, WordPress install can be automated by how you want it (by uploading a single file and loading that in the browser provided that you provide database connection details to it somehow.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "customization, ftp, installation" }
only show container with next/prev links if they exist? hey guys, i know there is something like `if ( function_exists('')` is it possible to use that with `next_posts_link()` and `previous_posts_link()`. The reason I'm asking that is that I have something like <div class="navigation"> <div class="next-posts"><?php next_posts_link('&laquo; older') ?></div> <div class="prev-posts"><?php previous_posts_link('newer &raquo;') ?></div> </div> In my case div.navigation has a colored background and a fixed height. So even there is no next or perv post this div.navigation appears. I wonder if I can only display this if there exists a next or prev post? Any idea how to do that?
Check out this link: < :)
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "php, query, functions" }
How can I remove links from the function "get term list"? <?php echo get_the_term_list( $post->ID, 'people', 'People: ', ' ', '' ); ?> returns something like this: People: <a href="person1">Person1</a>, <a href="person2">Person2</a>, ... How can I make it return the same thing without links like this: People: Person1, Person2
It may be easier to just write the list manually, something like: <?php $terms = wp_get_post_tags( $post->ID ); //For custom taxonomy use this line below //$terms = wp_get_object_terms( $post->ID, 'people' ); foreach( $terms as $term ) $term_names[] = $term->name; echo implode( ', ', $term_names );
stackexchange-wordpress
{ "answer_score": 11, "question_score": 2, "tags": "taxonomy, terms" }
Remove wptexturize from a shortcode? Is there a way to remove `wptexturize` only for a certain shortcode?
There is a clue in `wp-includes/formatting.php` in the function `wptexturize`: $default_no_texturize_shortcodes = array('code'); ... $no_texturize_shortcodes = '(' . implode('|', apply_filters('no_texturize_shortcodes', $default_no_texturize_shortcodes) ) . ')'; Try using this filter to add a shortcode to the array: function my_no_tex( $shortcodes ) { $shortcodes[] = 'someshortcode'; return $shortcodes; } add_filter( 'no_texturize_shortcodes', 'my_no_tex' );
stackexchange-wordpress
{ "answer_score": 5, "question_score": 5, "tags": "shortcode, formatting" }
Add class to Reply button in Comments area Under each comment there is a link called 'Reply'. I want to add a class to this link. It's default class is `comment-reply-link`. How can I do so? I am creating my own theme and I don't want to manually edit files inside the wp-includes directory.
In your comments.php template file use `wp_list_comments` and set the parameter `callback` to your defined function that will generate the template. Inside the function you can style the comment reply link. wp_list_comments codex Further reading on comment display
stackexchange-wordpress
{ "answer_score": 3, "question_score": 4, "tags": "comment form" }
Hide reply button after moveForm is called When user clicks on Reply button for a specific comment, how can I then hide the reply button under said comment? Do I have any access to the javascript onclick function that it calls?
Ended up using jQuery to solve this. The form moves around using javascript anyways so it doesn't break anything for users with js turned off. //when reply button is clicked hide it $(".comment-reply-link").click( function() { $(this).hide(); }); //when cancel button is clicked reshow reply button $("#cancel-comment-reply-link").click( function() { $(".comment-reply-link").show(); });
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "javascript, comment form" }
How much will mounting wp-content on a separate NFS server impact performance? I'm thinking of using multiple web servers with a load balancer in a big WP install. The database will be on a separate server and that's the easy part. Trickier is files in blogs.dir, and to a lesser extent, the themes and plugins folders. So I plan to use a separate NFS server, either for all of wp_content or just for blogs.dir. But I'm worried about the performance impact of having these files available over the local network. If you have done this I would love to hear your thoughts on... * Is it wise to share all of wp-content in this way? If not, how about just blogs.dir? * How much of a performance trade-off was it? * Do you have any suggestions based on your experience? Thanks.
It would depend on the speed of the NFS and the speed of the local network. If your using an object cache like APC the plugins and theme file folders will not be effected because they will be loaded in memory. A better solution would be to use a CDN or even create your own CDN using a lightweight static file server like Nginx for blogs.dir. W3 Total Cache has built in transparent content delivery network (CDN) integration with Media Library, theme files and WordPress static files. If you do decide on an NFS there are steps you can take to optimize the performance like the use of NonVolatile RAM, mounting the file system as RAID 0 and making sure you are using UDP instead of TCP.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "performance, uploads" }
Why is ?doing_wp_cron being appended to my URLs I'm finding this string appended to the end of my URLs sometimes: /?doing_wp_cron Does anyone know what it for? How can I remove it?
It's a sign that you have `ALTERNATE_WP_CRON` defined in your `wp-config.php` In order to do some background processing (like publishing scheduled posts), WordPress redirects you to the URL with `?doing_wp_cron` appended.
stackexchange-wordpress
{ "answer_score": 19, "question_score": 17, "tags": "urls, wp cron" }
Is it possible to sort posts by vote using the GD Star Rating plugin? Anyone has experience using the GD Star Rating plugin? and make a loop that sorts posts by vote/stars?
First 2 results on googling for "gd star rating sort posts by rating' are: * How to Sort Post by Gd Star Rating Mirror * How to reorder posts Mirror > Few examples: > > > query_posts("gdsr_sort=rating"); > query_posts("gdsr_sort=review&sort_order=asc"); > query_posts("gdsr_sort=rating&gdsr_multi=3"); > query_posts("gdsr_sort=votes&sort_order=asc&gdsr_multi=3"); >
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "plugin gd star rating" }
Wordpress 3.1: Videoplayer implemented? when using "insert video" from the post-editor - i'm only getting a normal hyperlink to the video - is it possible to display a flash-videoplayer instead? is there a default videoplayer in wordpress or will i need a plugin? in that case - which plugin is recommended? thx
Indeed, the "Insert video" action does not do much beyond creating a link. WordPress does not contain a generic player that can play any video hosted anywhere on the internet, but it does support something better: embedding via oEmbed. This means you can put the URL of the video page in your content, and it will replace it with the proper embed code - if the video site supports oEmbed (most popular sites do), and if WordPress is configured to allow embed from this site (but you can enable oEmbed autodiscovery or use a plugin like Embedly to add more sites). The support in the editor could be better, but this is probably the most future-proof way to embed videos in your posts.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "videos, flash" }
How to add an export function to a custom Option Theme Page I'm creating a new Wordpress template and I have a question: I've added a custom Option Page to my new template (you can see what I'm doing Here and Here) but now I would like to add a new function. Do you know Si Contact Form? In this plugin the end user can download a backup of all the settings and Upload it on a different website. I would like to be able to add the same function into my new option page. I know how to backup my settings logging to phpMyAdmin but sometimes end-user can't login to phpMyAdmin or simply it's better that he/she doesn't login to phpMyAdmin :-). Have you got any solution to this? Actually all my custom functions are named: 'appaqua__zona1c';'appaqua__zona1x' and so on... my theme shortname is appaqua. Please by kind with me, I'm not a professional programmer and I'm really sorry if I used wrong words to explain what I need. Thank you very much to all!
The easiest way would be to look at the code of Si Contact Form (since it already does what you want) and use the same kind of system. Shortly, you'll need methods to do the following: * Create an XML (or other format) document of your theme options. * Save/Export the XML document. * Import the XML document (There's no point in exporting if you can't import it again). If you want to use Si Contact Form as an example, the backup routines are in: * < Basically, it just outputs a serialized version of your options in a file. You can then upload the file to your admin page, parse the serialized string of options, and restore whatever you need from a backup. The backup scripts for Si Contact Form are in the `si_contact_form_backup_restore()` function of this file: < (Most of the way down the page). It just reads the file, parses the options, and sets them in the database as needed.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "functions, theme options, export, phpmyadmin, settings api" }
Retrieving all Links from a Post? i'm using the default "insert video" function from wordpress (which inserts a normal hyperlink to the video only) and would like to replace that link with something else like a video player. my question: what's the regex pattern for grabbing all links inside a post? thx
I'll answer your question below, but have you looked at using embeds? Look here for more information: < The simplest regex for this would look something like `http\:\/\/.*\b` Here's an example of it in action: <?php $file = 'test.txt'; $fp = fopen($file, 'r'); $contents = fread($fp, filesize($file)); $matches = array(); preg_match_all('/http\:\/\/.*\b/', $contents, $matches); print_r($matches); ?> Where the file I reference looks like this: and the return looks like this: Array ( [0] => Array ( [0] => [1] => [2] => ) )
stackexchange-wordpress
{ "answer_score": 5, "question_score": 2, "tags": "links, regex" }
How to show last post of each website of a MU wordpress in HomePage I'm running a Wordpress MU website and each website has its own "life" but now I would like to show last X posts of each blog of my network on the homepage. I know how to do it using Feeds and a plugin named FeedPress but this is a "dirty" way to do it. Is there anyone who knows how to do it?
If you've already got a solution that works using FeedPress you might as well stay with that, there isn't a particularly clean way of aggregating multisite posts into a single blog. One alternative is to use the Sitewide Tags plugin, but given what you want to do, you should probably stay with what's working.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "posts, multisite, homepage, settings api" }
How to add an option page to custom post type? As the title says, I have not found any function to add an option page to a particular custom post type. I would like to keep the option page related to a custom post type grouped together in its own panel, instead of adding it to the "Setting" panel, for example. Any suggestion? Thank you
use add_submenu_page() and as the pass add_submenu_page('edit.php?post_type=YOUR_POST_TYPE_NAME',....);
stackexchange-wordpress
{ "answer_score": 6, "question_score": 5, "tags": "custom post types" }
URL rewrite based on a custom field value I'm working on a migration from another CMS to WordPress. The old site had terrible SEO-unfriendly URLs in the format ` We have imported all the posts from the old site into WordPress and are storing the `lid` as a custom field. We would love the old URLs to still work if possible, but as there are about 3,000 posts using .htaccess is out of the question. So my question is: how would I create a rewrite rule that extracts the `lid` value from the URL and redirects to the post that contains it in the custom field? (the `lid` value is unique, so there are no worries about more than one post with the same custom field value) Many thanks Simon
here is an idea, first add `lid` to query_vars: add_filter('query_vars', 'lid_query_vars'); function lid_query_vars($vars) { // add lid to the valid list of variables $new_vars = array('lid'); $vars = $new_vars + $vars; return $vars; } then use `parse_request` hook to create your redirect add_action('parse_request', 'lid_parse_request'); function lid_parse_request($wp) { // only process requests with "lid" if (array_key_exists('lid', $wp->query_vars) && $wp->query_vars['lid'] != '') { $args = array('meta_key' => 'lid', 'meta_value' => $wp->query_vars['lid']); $redirect_to_post = get_posts($args); foreach($redirect_to_post as $p){ $link = get_permalink($p->ID); wp_redirect( $link , 301 ); exit; } } }
stackexchange-wordpress
{ "answer_score": 6, "question_score": 4, "tags": "permalinks, url rewriting, redirect, migration" }
How to add classes in the wp_list_category parent link How do I add classes in the wp_list_category , I know the wp_list_categories('title_li='); generates classes , but I want to add a class in the parent category link <ul> <li><a href="#"> link1</a> </li> <li><a href="#">link2 </a> </li> <li><a href="#">link3 </a> <---how do I add a special class here <ul class="children"> <li><a href="#">link3 children </a> </li> <li><a href="#"> link3 children</a> </li> </li> </li> </ul> Im planning to use a jquery UI accordion in here, please help. thank you -edit-- problem solved by Paul , thanks man
jquery accordion accepts an option called header that allows you to provide a selector to designate the items you want to act as the accordion headers. $('li.categories > ul').accordion({ header: 'li.categories > ul > li' }); * * *
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "customization, link category" }
Thumbnail and image management I always though the the image manager into wp is not really good... I need to be able to generate square or custom size when i like where i like, much like **TimThumb** that generate thum on the fly... but a little complicated... what do you use or what is the best plugin...
I have find this faboulous article... just copy/paste it here for future reference : <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "images, post thumbnails" }
Will post id change when migrating to new site? I'm creating a rather complex plugin that synchronizes posts from your server with a thirdparty server. I need to know, if you migrate your wordpress server to a new site, "can" the post ids change? If so is there another unique id? Also, is there any other instance where a post id could change? If the id does change and there is no other unique id then chances are I'll just do some complex md5 signature checking and string comparison if need be.
The `wp_posts` table has a `guid` field, which should be globally unique, and survive migrations. It is formed by taking the initial post URL, and never changed after that (when you change the title, change the website address, or migrate the posts). This should be pretty safe to base your synchronisation code on.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "migration" }
TinyMCE Button to Insert Multiple Lines of Text? Is there a way to get my custom TinyMCE button to insert multiple lines of text? Ultimately I am making a "Premade Themes" button where a user will select a theme and it will insert about 6-8 different shortcodes with one click and they can edit the shortcodes accordingly.. A problem I'm having is that all of these shortcodes get put in one line. Here's the code I use that actually pastes the shortcodes: `tinyMCEPopup.editor.execCommand('mceInsertClipboardContent', false, {content : 'the shortcodes go here'});` Any help is appreciated!
This should be as easy as adding `<br />` between shortcodes or every time you want to add a new line and also if you are inserting content you should use `mceInsertContent` instead of `mceInsertClipboardContent` unless you are actually getting the content from the clipbard, so: tinyMCEPopup.editor.execCommand('mceInsertContent', false, '<p>[shotcode1]<br/>[shotcode2]<br/>[shotcode3]</p>'));
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "javascript, tinymce" }
Fastest way to loop through all posts? I need to run a background process in a plugin that does some work on ALL the posts in a person's database once the plugin is installed. I'm very new at working with wordpress so my research has shown that I can use the wp query or I can use "the loop". Since I'm going through absolutely every single post speed is of the essence. I need to check the title, body, categories, meta tags, publish state and password protected. So based on this, which one of these would be fastest?
"The Loop" is just a name given to the `while (have_posts()): the_post();` loop used to iterate over an array of posts returned by `WP_Query()`. The other function used for querying posts is the get_posts() function, which returns a simple (non-extended) array which you can loop through with a `foreach` loop. I don't think it matters a whole lot; however, if you're nitpicking, the `get_posts()` method is slightly faster and less memory-intensive, since it doesn't call `setup_postdata()` (which populates the template tags, etc.) on every post it loops through. Either way, you're probably going to run out of memory on some setups with thousands of posts... Make sure you build in fallbacks in that case.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "plugins, posts, loop" }
Check if wp-login is current page How can I check if the current page is `wp-login.php` or `wp-signup.php` ? Are there more elegant solutions than using `$_SERVER['REQUEST_URI']` ?
Use the global `$pagenow`, which is a common global set by WordPress at runtime: if ( $GLOBALS['pagenow'] === 'wp-login.php' ) { // We're on the login page! } You can also check the _type_ of login page, for example registration: if ( $GLOBALS['pagenow'] === 'wp-login.php' && ! empty( $_REQUEST['action'] ) && $_REQUEST['action'] === 'register' ) { // We're registering } **Following code is considered legacy and should not be used** (`wp-register.php` was deprecated & subsequently removed quite a while back): ~~ if ( in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) ) ) run_my_funky_plugin(); ~~
stackexchange-wordpress
{ "answer_score": 71, "question_score": 55, "tags": "pages, login, user registration, conditional tags" }
How to get an image transferred via FTP or script to appear in Media Manager? I've got a plugin that transfers some files over to the uploads folder of the site in which the plugin is installed. It works fine, however, the images are not appearing in the Media Manager. I expect some database registration is involved. Given the script below which copies the files into the directory, what command would I need to add to the loop to register each image for the media manager? foreach(new RecursiveIteratorIterator($rdi) as $files) { if ($files->isFile()) { $imagepath = $files->getRealPath(); $image = basename($files->getPathname()); copy($imagepath, $my_target_folder.'/'.$image); } }
add this to your for each and $filename to each file, $wp_filetype = wp_check_filetype(basename($filename), null ); $attachment = array( 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)), 'post_content' => '', 'post_status' => 'inherit' ); $attach_id = wp_insert_attachment( $attachment, $filename, 0 ); // you must first include the image.php file // for the function wp_generate_attachment_metadata() to work require_once(ABSPATH . "wp-admin" . '/includes/image.php'); $attach_data = wp_generate_attachment_metadata( $attach_id, $filename ); wp_update_attachment_metadata( $attach_id, $attach_data );
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "plugin development, images, media library" }
Custom template for each page I am creating multiple pages in Wordpress. I understand I can style these with page.php. Is there any way I can style specific pages with custom templates? So for example if I had page About Us I would want a sidebar that has links to our profiles. If I had page Contact Us I would want a sidebar that has links for emailing us.
there are a few way you can do that: * Template Hierarchy \- each page with is own theme file using page-{ID/slug}.php * Custom Page Templates \- Individual Pages can be set to use a specific custom Page Template from the edit screen. but if you are just looking to change whats on the sidebar then there are a few plugins that can help you with that: * Widget Logic \- lets you control on which pages widgets appear. * Dynamic Widgets \- lets you dynamicly place the widgets on WordPress pages. and there are even plugins that let you display the whole sidebar on a page to page basis: * Sidebar Generator * Per Page Sidebars * Custom sidebars
stackexchange-wordpress
{ "answer_score": 5, "question_score": 2, "tags": "page template" }
TEMPLATEPATH without the theme name? No THEMEPATH constant? Is there a way to get a path to the themes directory without the current theme in the path? ie, in a standard WP install, I would want a reference to: > C:\xampplite\htdocs\sitename/wp-content/themes/ But the TEMPLATEPATH constant returns... > C:\xampplite\htdocs\sitename/wp-content/themes/currentActiveTheme
dirname( STYLESHEETPATH ); That will return the theme directory. **Never** assume `/wp-content/` below ABSPATH. I’m using often a different directory and domain for `wp-content` to enable cookieless requests to theme files. Bad plugins and themes break terribly in such cases. ### Addendum Or use `get_theme_root()` for the file path and `get_theme_root_uri()` for the URI. Both are defined in `wp-includes/theme.php`.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 0, "tags": "plugin development" }
Special purpose photos with each post How would I grab a photo, that has been added to a post, and use it elsewhere on a site when there have been several photos added to the post? For example, my site has a blog (Wordpress) and a non-blog section. I want to pull one image from my latest post for use in this non-blog section. Keep in mind that there might be multiple photos associated with the post. The trick to me seems to be how to designate one specific photo of however many are associated with a post as "the photo" that will be used in the non-blog portion of the site. Ideas? Suggestions?
Well one photo can be assigned as the thumbnail as you can see in the post editor screen. Otherwise as the comment above suggested create a post meta field for example 'my_post_image' and place the id of the image attachment in that field. That is how WordPress saves the post thumbnail (look in the database, something like _post_thumbnail is the meta field name).
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "images, post thumbnails" }
Produce a plain page with only a message I am integrating a payment gateway into a distributed wordpress plugin. The notification page (page that the gateway sends info to after the payment has been made) requires only a message of "success" or "fail" to be printed. In that page, I need access to the database and some org options. Can someone please tell me how to produce such a page (i.e. no menu, no header, no footer and etc.)? The gateway in question is alipay.
See < Just don't include `get_header()`, `get_siderbar()`, `get_footer()`.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "pages" }
Making a Shortcode [NEXT] and [PREVIOUS] to place into specific posts for post navigation I really need some help, I dont know where else to turn with this request. I'd like to add a shortcode to one of my posts. The template tags get_next_post() and get_previous will not work for me since I dont want post navigation on each post page and I want to control where it displays. In a DIV in an HTML structure I've created in a post. So what I need is to generate shortcodes from get_next_post() and get_previous_post()
this is very simple to do... // next function next_shortcode($atts) { // global $post; -unnecessary return '<div class="nav-next">'.next_post_link( '%link', '%title <span class="meta-nav">' . _x( '', 'Next post link', ' ' ) . '</span>',true ).'</div>'; } add_shortcode( 'next', 'next_shortcode' ); //prev function prev_shortcode($atts) { //global $post; -unnecessary return '<div class="nav-previous">'.next_post_link( '%link', '%title <span class="meta-nav">' . _x( '', 'Previous post link', ' ' ) . '</span>',true ).'</div>'; } add_shortcode( 'prev', 'prev_shortcode' ); Goodluck! Here for any question....
stackexchange-wordpress
{ "answer_score": 4, "question_score": 6, "tags": "shortcode, template tags, next post link" }
Is there any way of only retrieving posts with one or more thumbs up (GD star rating plugin)? I'm building a website that uses the GD star rating plugin. Right now, I'm using the following code to retrieve two posts of the current page (a custom post type called `bbp_topic`) and sort them by vote: <?php query_posts('gdsr_sort=thumbs&posts_per_page=2&post_parent='.$post->ID); ?> I would like now to only retrieve those post that have 1 or more thumbs up. Any suggestions?
`gdsr_ftvmin=1` is probably the query parameter you need
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "query posts, plugin gd star rating" }
Is there any way of changing the post order via user click? Is there any way of changing the post order, posts number, etc via user click? The same way you can choose displaying questions by time and vote here at StackExchange. How to accomplish that?
Check the WP Sort Plugin, it does exactly what you need: <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "links" }
What is the constant WP_USE_THEMES for? Regarding the `WP_USE_THEMES` constant, the Codex states: > If you are using The Loop inside your own design (and your own design is not a template), set WP_USE_THEMES to false. But what is the actual effect on WordPress from `WP_USE_THEMES` being set to true or false? I would like to know how it's used by WP.
This is only used in `template-loader.php`, to determine whether it should load a theme file or not. The normal "boot sequence" of WordPress (started in `wp-blog-header.php`) loads the plugins, parses the URL, executes a post query based on the URL, and calls the theme. This main post query is typically used in "The Loop". So if you want all the advantages of URL parsing but not display it using the site theme, you can set `WP_USE_THEMES` to `false` and it will not execute that final step.
stackexchange-wordpress
{ "answer_score": 40, "question_score": 39, "tags": "theme development" }
How to Disable Color Options? This question is related to my earlier question, but I think it's specific enough to qualify as a standalone question. I am modifying an existing theme (the Twenty Ten theme that ships with WordPress), and I would like to completely control the colors used. The Admin Screen allows the administrator to select a background color, and this seems to be implemented in one of the actions that are automatically registered to the `wp_head` hook (listed by Bainternet here). So I would like to do two things: * Remove the _Color Options_ menu from the Admin Screen when my theme is activated. Is this possible and if so, how would I go about doing this? (Links to documentation welcome!) * Remove the automatically registered action to wp_head that controls the color. Which action in particular would be responsible for this? (rsd_link, etc?) Thanks for your help.
In TwentyTen’s functions.php the custom background is added in twentyten_setup() which is called on the action `'after_setup_theme'`. So, in your child theme, the following should remove the option completely: // Higher priority to work after TwentyTen add_action( 'after_setup_theme', 'wpse12934_remove_custom_background', 20 ); function wpse12934_remove_custom_background() { remove_custom_background(); }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "theme development, wp admin, theme options, custom background" }
What is generating Similar Posts and Related Posts on my blog? I checked in my list of plugins, and I have nothing that seems like Related Posts or Similar Posts. Yet, at the end of my posts I find two very similar sections titled as such. Any idea how to turn one of them off, and how to understand what plugins are responsible for generating them?
Similar posts section has following comment in page source <!-- Similar Posts took 18.313 ms --> which quick search identifies as belonging to Similar Posts plugin. Nothing to identify "Related" section by. I'd try to search sources for that heading.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugins" }
Completely disabling widgets How do I completely remove widget support from a theme/plugin ? Like removing the _appearance -> widgets page_ , and prevent WP from loading widget classes and all widget-related stuff.
One option would be to simply flush the widget code out of the sidebar.php file, as well as the header/footer/post pages if they are using widgets. However, take a peek at this code snippet (courtesy of this site), which you can add to your functions.php file and will disable the widgets. I think this would be a cleaner approach if you're looking to change themes and sill have widgets disabled. <?php add_filter( ‘sidebars_widgets’, ‘disable_all_widgets’ ); function disable_all_widgets( $sidebars_widgets ) { if ( is_home() ) $sidebars_widgets = array( false ); return $sidebars_widgets; } ?> Note that this will only disable the widgets on your home page, so you'll need to find the additional conditionals for individual pages/posts/etc.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "widgets, wp admin" }
Importing old blog with regular posts into new custom post types I have 2 older WP blog installs with regular posts that I would like to bring over to a new blog. One of the older installs is for "news" posts and the other is for "blog" posts (I know this was not the best way of setting things up). In my new blog, I have created two custom post types ("news" and "blog") and I would like to import these two older installs into my new install's respective post types. Is there an automated way of doing this (perhaps a plugin) that would save me from manually re-entering all of these posts? I'm assuming that simply importing these will not allow me to mark them as a custom post type and instead would make them generic posts. Thank you! Jake
Try importing and then using a plugin (Post Type Switcher) to change the type. There are a few other plugins out there for this, I seem to remember one which would convert multiple posts, but I couldn't find it just now.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 6, "tags": "custom post types, import" }
remove sanitize_title() for register_taxonomy() **Update** From reading the answers, i think i didn't make myself clear, so i try to post it again. I register taxonomies from data from parsed xml files. The arguments passed _should_ be absolutely correct. What i wanted to know is on which of the arguments of the `register_taxonomy()` function the `sanitize_title()` function get's called. I currently got an error and need to figure out which of the parameters is wrong.
First: **Sorry** , if i wasted your time. The problem couldn't have been guessed by anyone and was lying in the middle of my class. I simply build an array where i pushed all needed stuff into. This array was rebuilt before i pushed it into the `register_taxonomy()` function. There i simply forgot to unset those parts i didn't need anymore. @MikeSchinkel @One Trick Pony - please add some answer here, so i can upvote you for your efforts. Thanks to everybody :)
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "custom taxonomy" }
"Order" doesn't work in custom loop? I have a custom loop (used in a shortcode) that lists items from custom post type. Everything works fine but "order" for posts doesn't work, no matter what I type as order attribute on post page - items are always displayed the same way (the most recent first and the oldest last). Why doesn't "order" work in my case? The loop looks like: $loop = new WP_Query( array( 'post_type' => 'images', 'paged' => get_query_var('paged') ? get_query_var('paged') : 1, 'posts_per_page' => $per_page, ) ); while ( $loop->have_posts() ) : $loop->the_post(); (my code) php endwhile;
Add `orderby` clause to your query! Here is the complete list of order parameters $loop = new WP_Query( array( 'post_type' => 'images', 'orderby' => 'menu_order', 'paged' => get_query_var('paged') ? get_query_var('paged') : 1, 'posts_per_page' => $per_page, ) ); This query order by the menu order that you have specified in your pages
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, loop" }
Find Posts based on Child Post value I am creating a plugin that adds two custom post types, one of which will always be a child of the other. The parent post type is for Events, the child for Performances. Before entering the Loop, I'd like to be able to find a set of Events that have Performances on a specific date. Performance date is stored as a meta field on the Performance post. The Loop would then list each Event matched, like in a standard post archive loop. My preference is to query the Event post type, since that strikes me as easier to manage for pagination, but if there's a better implementation that simply involves querying performances, I am open to that, but I'd like to see if there's a facility for limiting a query based on a field in the child post.
Child posts are related to their parents (through the "post_parent" field), and not vice versa. So you would have to query your child post type first, then get the parents of all the results. // obviously these variable names and key names might not apply, // change them as necessary $performances = get_posts( array( 'meta_key' => 'the_performance_date_custom_field', 'meta_value' => $date, 'post_type' => 'performance' ) ); // extract the parent post ID's from each of the returned performances $event_ids = array_map( create_function('$post','return $post->post_parent'), $performances ); $event_ids = array_unique( $event_ids ); // dump any duplicate events // and finally, get the events from their ids $events = get_posts( array( 'post_type' => 'event', 'post__in' => $event_ids ) );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, query posts, wp query" }
get listed category's id? ok - so i'm listing categories and their sub-categories. How can i get the ID of the category that's being shown with a function? ( i know what it is in the admin ) ie /category/events/women-in-art/ women-in-art-ID = ? any help appreciated! Dan.
How about get_query_var('cat'). I think that should get the ID of the current category.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "categories, list" }
Breadcrumbs - get the author? I have my own function called breadcrumbs(). In it I call is_author() to determine whether I am on an author page. If true I would like to know _which_ author's page I am on. I tried the_author(), but nothing came up. I looked through the WP codex also. Can someone please help?
Call `echo $GLOBALS['wp_query']->query_vars['author_name'];` and it should show you the author. You can also `echo $GLOBALS['wp_query']->post->post_author;` or `echo $GLOBALS['wp_query']->queried_object->post_author;`. _hope i didn't mix up with arrays and objects._
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "author, codex" }
How to create rewrite endpoints it in author.php? i'm trying to separate categories/subcategories in author.php so they each have their own endpoint link. It's very similar to this question BUT for the life of me I can't enable the plugin provided: How to set up sub-categories for author pages? The solution provided was this: < I've downloaded the file, it's instructions say "enable this plugin" ... but when i put it in wp-content/plugins folder it doesn't show up on the list. I've tried putting it in a folder, and just putting the .php file in plugins folder. But it doesn't show up on the list. **How can I enable this?** or if you have any other ideas on how to achieve these results i'd greatly appreciate it. Thank you!
Hi **@Pwn:** Add the text _"Plugin Name:_ * in front of the text _"Author Endpoints Example."_ You may need to remove the leading asterisk ("*").
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "url rewriting, author" }
How to check current URL for endpoint in a template file? What's the best way to check current url for endpoint in a template file? I have a plugin that creates endpoints in **author.php**... so now i'm trying to check in **author.php** so that only certain code is executed if the URL ends in a specific endpoint? `example.com/author/username/endpointA` `example.com/author/username/endpointB` The idea is that each endpoint has different content. Thank you!
Check out this tutorial for query variables: < Essentially what you will be adding is a custom query variable with value either A or B to show different content. I.e. /author/username/contentA is actually index.php?author=username&customqueryvar=contentA.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "url rewriting, urls, author" }
How can I allow the Editor Role to change Theme Settings? I've just setup a new Blog for a friend and thought it's better to not give him Administrator Access right away as a precaution. I created a new user as Editor therefore. But then I saw that this user can not change the Theme Settings like Background and Header. Is there an easy way to allow the Editor Role to edit any theme settings in Twenty Ten or a Child of it? He should basically be able to do anything an Administrator can do reg. the Theme, probably even changing themes.
you can add capabilities to the editor role using the role object and add_cap from you functions.php <?php // get the the role object $editor = get_role('editor'); // add $cap capability to this role object $editor->add_cap('edit_theme_options'); ?> you can also remove capabilities: $editor->remove_cap('delete_posts'); just take a look at the **list of capabilities** and what each one means.
stackexchange-wordpress
{ "answer_score": 22, "question_score": 23, "tags": "themes, user roles" }
What is the best Captcha plugin for registration? I'm suffering from the issue of lots of fake registrations for my site. I'd like to add a captcha for registrations. What is the best plugin that will require a captcha at registration? Recommendations based on real installs are most appriciated! Also: I'm using the most up-to-date install of WP.
My favorite captcha plugin is reCaptcha. The captcha images are scans from old, damaged books. A computer identifies possibilities with OCR, then the user, in correctly filling out the captcha, confirms it. It helps digitize whole books this way. It's an initiative by Google. Read about them on their website.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 7, "tags": "captcha" }
How can I disable the update notice for non-administrators? As I already told, I'm setting up a Blog for a friend. Next to not being him an administrator but an editor that can make changes to theme options) I have an additional question. I don't want him to worry about updates as well nor do I want him bothering me, but the problem is, editors do see a slightly changed variant of the update nag. Is there a way to disable those for non-admins? It's just the case that we normally do know about Wordpress updates even before they get packaged and released.
You may have to adjust the capability. add_action( 'admin_init', 'hide_update_msg', 1 ); function hide_update_msg() { ! current_user_can( 'install_plugins' ) and remove_action( 'admin_notices', 'update_nag', 3 ); }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "user roles, updates, customization" }
Activate theme via plugin script? I have a plugin that installs a folder of themes and other plugins into the WP site during plugin activation. I would like to place script into the plugin which will activate one of the themes that the plugin installs. Can someone post a quick example of script that registers and activates a known theme via a plugin's activation script?
switch_theme() should work: function myplugin_activate() { switch_theme('default', 'default'); } register_activation_hook( __FILE__, 'myplugin_activate' );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugin development" }
Contact Form 7: Email custom HTML inputs or make a field readonly I am trying to email a custom input <input type="text" name="total" id="total" class="wpcf7-text" readonly="readonly" /> I tried `[total]` but it does not work. Or isit possible to make a field readonly with WPCF7?
Contact form 7 is one of my favorite plugins , now after I've said that you can either create your own module to add a filed of "readonly" by following this tutorial < or maybe even digging through Contact Form 7 Modules plugin to see how to add new modules, but a much easier solution would be to create a regular text filed and use JQuery to add the readonly attribute `$('#inputId').attr('readonly', true);`
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "plugin contact form 7" }
How would I increase the Author Role to be able to add a new category? How do I increase Author Role permissions to be able to add Categories? Other solutions welcome. We just need guest authors to be able to add categories while ensuring there is not already a existing appropriate category.
The easiest way is to use a plugin like Capability Manager or User Role Editor
stackexchange-wordpress
{ "answer_score": 4, "question_score": 4, "tags": "categories" }
Is comment metadata included in the export file? If I would export a WordPress database, posts and comments etc. are saved to an XML file. Would comment metadata be included in this XML file? I.e. the table `wp_commentmeta`, mentioned here: < Here: The WordPress eXtended Rss (WXR) Export/Import, XML Document Format Decoded and Explained Export/Import, XML Document Format Decoded and Explained") I found some info on the export file format, and the columns in `wp_comments` are mentioned, but there's no mentioning of any columns in `wp_commentmeta`. **Edit:** Background: I'm planning to write a new commenting system for WordPress, and I'd like to be able to import/export comment data between various blog platforms. (E.g. Blogger and others.) And I think I need to use the comment metadata table. **/Edit** Kind regards, Magnus
My latest export from my blog (WP 3.3.1) now has the commentmeta in the XML. It's in this format: <wp:comment> <wp:comment_id>...</wp:comment_id> ... <wp:comment_user_id>0</wp:comment_user_id> **<wp:commentmeta> <wp:meta_key>name_of_meta</wp:meta_key> <wp:meta_value><![CDATA[value_of_meta]]></wp:meta_value> </wp:commentmeta>** </wp:comment> I was looking for information on it while trying to write an exporter from another system. Not much information available online so I tried an export from a well-used blog--it was there!
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "comments, export" }
How do you filter get_media_items by mime type in a custom media upload tab? I've gotten as far as creating my new tab and getting it to show up and I've taken a copy of the gallery screen (I'm making an audio plugin with a playlist feature). The list of media items shows up fine but I can only get it to show just the audio files when I don't pass a post ID into the `get_media_items()` function like in the media library tab. How I can retrieve a media items list using `get_media_items()` where the post_parent field is set and the post_mime_type matches 'audio'?
The answer ended up being to copy that function and filter the results it returned. It's hacky but until there are more hooks/filters available in that section of the core there's no better way :(
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugin development, media library, uploads" }
WP navigation list classes I'm using this code to display my menu: <?php $menu_args = array( 'container' => '', 'menu_class' => '', 'menu_id' => 'main-menu', ); wp_nav_menu($menu_args ); ?> It works totally fine, but I don't know how to get rid of all these classes attached to every li in my menu? Example: <li id="menu-item-227" class="menu-item menu-item-type-post_type current-menu-item page_item page-item-77 current_page_item menu-item-227"> It's pretty long, isn't it? I don't need classes and even IDs here at all, since my menu has one already. Any ideas?
you can use `nav_menu_css_class` filter hook to remove the classes: add_filter('nav_menu_css_class' , 'my_nav_menu_remove_class' , 10 , 2); function my_nav_menu_remove_class($classes, $item){ $my_class = array('menu-item-class'); return $my_class; }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "menus" }
How do I display custom post types through a common taxonomy? I have posts and I have recipes. Recipes is a custom post type. Recipes make use of the category taxonomy and a newly added recipe has been categorized under beer. When I browse the listing page for the category beer I see all my previous posts categorized under beer while the new recipe does not appear. How do I link custom post types through their taxonomies? Or, how can I show all post types under a single category?
You can use pre_get_posts hook to add your custom post type to the query function include_recipes( $query ) { if ( $query->is_category ) { $query->set( 'post_type', array('post','recipes') ); } return $query; } add_filter( 'pre_get_posts', 'include_recipes' );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "custom post types, taxonomy, links" }
Plugins to generate CSS Sprites? I see that w3 total cache can't offer CSS sprite generation. Is there another plugin that can complement this feature? Thanks. update: I didn't mean that w3 total cache doesn't allow CSS sprites to be used, but that it doesn't generate them automatically as a way to improve sites performance. My question is what plugins DO offer that capability.
Are you asking about how to create css sprites? Try < if the manual way seems too time-consuming. But yeah, not really a WordPress question.
stackexchange-wordpress
{ "answer_score": 2, "question_score": -1, "tags": "plugins, css, performance" }
How do I display posts by day? <?php $my_query = new WP_Query("cat=1&day=''&posts_per_page=-1"); ?> <?php while ($my_query->have_posts()) : $my_query->the_post(); ?> I'm trying to display all posts from a single day on my homepage, restricted by category. The code above is what I'm using, but I've tried a bunch of variations on listing the current day and can't seem to get it to display posts only from the current day. I'm sure I'm missing something completely obvious, but how do I get this working to restrict posts by date? Although getting the homepage figured out is my first challenge, I also want to have my individual day archives set up in a similar way.
You'd have to specify day, month, and year to get today's posts: $my_query = new WP_Query( array( 'cat'=>1, 'year'=>date('Y'), 'monthnum'=>date('m'), 'day'=>date('d'), 'posts_per_page'=>-1 ) ); Leaving day blank just doesn't set that query var, so its not restricting your query at all.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "date time" }
wp_logout Not Logging Me Out Here is what I'm doing: wp_logout(); var_dump(is_user_logged_in()); var_dump returns: bool(true) Why is wp_logout() not logging me out?
**wp_logout()** calls clear_auth_cookie(), which expires all authorization cookies set. It doesn't change the value of the global **$current_user** variable. So technically you're still logged in for the duration of the script. If you're using `wp_logout` in your own code, its probably best to `exit` or `wp_redirect` immediately afterwards. You can call `wp_set_current_user(0)` after `wp_logout()` to manually log the user out instantly, if you need to continue executing PHP but don't want the user to be logged in
stackexchange-wordpress
{ "answer_score": 6, "question_score": 3, "tags": "logout" }
Displaying year, month and day archives differently I'd like to display daily archives differently than monthly/yearly archives. How do I check to see if the archive template is being pulled for a daily archive vs. a monthly/yearly archive?
**Conditional tags** FTW. * is_month() : Currently viewing a monthly archive * is_day() : Currently viewing a single day archive * is_year() : Currently viewing a yearly archive * is_time() : Currently viewing a time-based archive (hourly, minute, or even seconds) * * * So to test for each of these conditions, add something like this to your **archive.php** (or whatever template is being used for your archive pages): // Check what posts were returned in order to find what date the archive is for global $posts; $archivedate = strtotime( $posts[0]->post_date); if (is_day()) { echo "Daily archive: ".date('m/d/Y', $archivedate); } else if (is_month()) { echo "Monthly archive: ".date('F Y', $archivedate); } else if (is_year()) { echo "Yearly archive: ".date('Y', $archivedate); }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "archives, date time" }
Use mysql_query instead of $wpdb query I have a custom table inside my wordpress database called test. What if i query this table using mysql_query() instead of using for example $wpdb->get_results() Will this affect my performance? Ty very much:)
Simple and short: * mysql_query() = **Faster!** * $wpdb->get_results() = **Safer!** But in most cases since `$wpdb` is a global object and already in the memory using it will be be as fast as `mysql_query()`. > Will this affect my performance? It can affect for better performance changes but they would be minor changes that its just not worth it.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "query, wpdb" }
Querying posts only if the current page is not paged? For example, I want to query posts in a page. But I don't want to show them when the user clicks the pagination links. Pretty much like what happens in Youtube. You only see the Top comments in the first page but when you click `Next` they disappear. Any suggestions to accomplish this? URL example: Query the posts if it is the first page: example.com/taiwantalk/forums/topic/technology-topic-11/ Don't query them if it is the second page or any other: example.com/taiwantalk/forums/topic/technology-topic-11/page/2/
The current page number is available in a global variable `$paged`. if ( ! isset ( $GLOBALS['paged'] ) or ( $GLOBALS['paged'] < 2 ) ) { // run your code }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "query posts, pagination, paged" }
New wp menu menu styling Ok ,i am not a great fan of the menu of WP, but now it manage this inside pretty ok, i have to make theme that use that menu. Now for styling i am a bit challenge... here is the problem... the menu should look like | page1 | page2 | page 3 | Do you see the problem, the border, let say each * will be style with border right 1px that work but first item will need a special class for border left Question. How do i know that it's first or last item in the menu to style it properly... or what is your way to style that type of menu...
Are you using CSS3? You could use: ul#navmenuid:first-child { border-left: 1px; } Or you could use (any LI that immediately follows an LI): ul#navmenuid li { border-left: 1px; border-right: 1px; } ul#navmenuid li + li { border-left: 0; } Or you could use (any LI that follow an LI, even if not immediately): ul#navmenuid li { border-left: 1px; border-right: 1px; } ul#navmenuid li ~ li { border-left: 0; } Lots of options via CSS, really...
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "menus, css" }
Empty RSS Feeds When i try to access feeds for tags,categories and authors, i get empty list. If i try to open feeds for the site, i get "Page not found" **Empty Feed:** < < **Page not Found :** < I had tried fix rss feed plugin. But it dint solved my problem too. Please help.
As per @Zeo suggestion, i activated default wordpress theme (Twenty Ten) -> I opened feeds then -> it was getting opened properly. I again to switched my theme without any changes. And it started working. If someone knows then please reason behind this.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "rss, feed" }
How to load a new template page according to a particular URL? I want to load some of the pages(not wordpress page, a template file other than wordpress's default template file) according to the url came on the address bar. for instance, I have page in my template file ie my_account.php to show my profile pic and other informations from to my wordpress pofile. and it is placed in my defaut theme folder /themes/mytheme/my_account.php When the url is ` then I need to load the above page. Something like if ` then load the register.php from my theme folder. I'm using custome permalinks option. ` So How can I configure and load the template according to the url, how to controll this by using a plugin.
You should be able to use template_redirect. I haven't tested it though, should be something like this. function page_redirect() { if ($_SERVER['REQUEST_URI'] == 'your_url') { require(TEMPLATEPATH . '/mY-account.php'); } } add_action('template_redirect', 'page_redirect');
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "plugins, custom post types, plugin development, customization, theme development" }
How to make widgetized footer styles be inherited from body? I'm making a WordPress site using the Thesis framework. It has a widgetized footer area. I expect to be changing all the font styles frequently and don't want to have to change them in a few places every time to make the footer widget styles match the body styles. Does anyone know how I can make the footers styles (h3, text, li, a href) be automatically inherited from what I've set for the body styles? Thanks!
The footer is a child of the body element. It **does** already inherit all the styles. Find and remove all the styles which are ruling out the inherited styles. Tools like Firebug or Dragonfly will help you to find these rules.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "css" }
How to trigger 404 for custom query var? How can you trigger a 404 when using custom query vars? I've got re-write rules written for a custom query var, but if you were to request a URL for the query var that should technically be a 404 it returns a normal WP page, but no content, because nothing technically exists for the URL.
There is an action specifically for this: function my_parse_query( $wp_query ) { if ( $wp_query->get( 'my_custom_var' ) > 42 ) { $wp_query->set_404(); status_header( 404 ); } } add_action( 'parse_query', 'my_parse_query' ); That should load the 404.php template in your theme, if you have it. Otherwise, it will fall back to index.php. This will also trigger a HTTP 404 status code. For more information see parse_query.
stackexchange-wordpress
{ "answer_score": 10, "question_score": 3, "tags": "wp query, 404 error, rewrite rules" }
Can I ignore caching of a plugin in W3 Total Cache? I currently have a plugin that lets me display a random post in a widget. The problem is that if I activate w3 total cache it will only display that post as long as the cache hasn't been cleared. Is there a way to cache everything except this plugin? Sorry if the question is rather newbie, I just installed the plugin but haven't been able to find the answer anywhere. Thanks in advance!
You can try fragment caching, from plugin's FAQ: Edit your templates to with the following syntax to ensure that dynamic features remain so: Example 1: <!-- mfunc any PHP code --><!-- /mfunc --> Example 2: <!-- mfunc -->any PHP code<!-- /mfunc --> Example 3: <!--MFUNC --> echo rand(); <!--/mfunc --> Example 4: <!-- mclude path/to/file.php --><!-- /mclude --> Example 5: <!-- mclude -->path/to/file.php<!-- /mclude --> But my personal opinion is just to get rid of overly dynamic stuff. Unless it's key functionality (like in e-commerce) it's usually useless eye candy.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "plugins, widgets, cache, plugin w3 total cache" }
Can I add pages to my custom menu via script? My theme has a custom menu assignment... function my_register_my_menus() { register_nav_menus( array('header-menu' => __( 'Custom Header Menu' ) ) ); } ...and I'm creating an "installer" type plugin that, upon activation, I would like to hook into this custom menu and assign some pages to it as if they had been created manually. However, the menu API is pretty new and to date, I've been unable to find any examples of how to do this. I'm hoping someone here can give me some direction, examples or info on how to do it. Thanks in advance :-)
You can use `wp_nav_menu_{$menu->slug}_items` hook and add you link with a callback function, for example if your menu slug is `header-menu` then something like this: add_filter('wp_nav_menu_header-menu_items', 'add_my_extra_links',10,2); function add_my_extra_links($items, $args) { $newitems = '<li><a title="Test Link" href=" $newitems .= '<li><a title="Test Link" href=" $newitems .= '<li><a title="Test Link" href=" $newitems .= $items; return $newitems; } ## Update I guess you would need to call wp_save_nav_menu_items which is the function used to save the menu items to the database.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "plugin development, menus" }
How do you format the date as a two digit year? (ex. "10.12.10" instead of "10.12.2010") I did a pretty thorough search and found a couple of closed (and unanswered) topics on the WP forums. Does anyone know if this is possible? The codex doesn't specify this as an option. Thanks!
You use a lowercase y for a 2 digit year. For example (l, F j, Y) --> returns, Friday, September 24, 2004 and (l, F j, y) ---> returns Friday, September 24, 04
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "date time" }
Example of uninstaller routine to remove all custom theme options from wp_options All of my theme's custom options are preceeded with "mytheme_" + option. For example, mytheme_color1, mytheme_color2, mytheme_body_font_color, etc... I'd like to create a plugin that uninstalls all of the items in wp_options where the option is preceeded with "mytheme_" If you have a reference or example, please share it. Thanks in advance :-)
> All of my theme's custom options are preceeded with "mytheme_" + option. Not safe enough. Use set_theme_mod(), get_theme_mod() and remove_theme_mod() instead. You’ll find these and more related functions in `wp-includes/theme.php`.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "plugin development, theme development, uninstallation" }
How can a plugin create a page/form in the front end? How can a plugin create a page/form in the front end thats not listed in pages (if possible). it should only be accessed through a direct link.
See How do you create a “virtual” page in WordPress for the solution. This should work for your case as well.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 12, "tags": "plugin development" }
Is it not recommendable to stick with plugins that are no longer supported by the author for production sites? For example, I used the plugin Vote it Up but it haven't been updated since 2010-5-28. Now I moved to GD star rating which was last updated in January 6, 2011 (and still maintained by he author). Is it not recommendable to stick with plugins that are no longer supported by the author for production sites?
As for me key questions here are: 1. **Is plugin outdated?** Not using approaches and coding practices of current WP versions. 2. **When will it become outdated?** This can range from months (next WP version changes something relevant) to years (plugin does something simple on using common and basic hooks). 3. **Can you handle when it will become outdated?** Maybe you can maintain it yourself. Maybe you have budget to hire someone for that. Maybe it will ruin your site.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "plugins" }
Moving/dragging a metabox removes TinyMCE's content I added a TinyMCE editor to my plugin settings page, but once I move (drag) the metabox, editor's content get lost. (the TinyMCE editor is completely not editable until refresh) Here is how I added TinyMCE editor: add_action( 'admin_head', 'add_tinymce_editor' ); function add_tinymce_editor() { if ( function_exists( 'wp_tiny_mce' ) ) { add_filter('teeny_mce_before_init', create_function( '$a', ' $a["mode"] = "textareas"; $a["editor_selector"] = ""; $a["plugins"] = "safari,inlinepopups,spellchecker"; return $a;') ); wp_tiny_mce( true ); } } Any ideas what can cause this bug and how to prevent/fix it? Thanks.
I had a similar problem with radio buttons losing their status when I dragged a metabox on a settings page. I hacked together a workaround and posted it as a reply to the original wordpress trac ticket <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugin development, metabox, tinymce" }
Custom options below pages/posts editor? I want to add permanently boxes below Visual/HTML editor for each page/post. I've never played with custom fields before, and I'm not sure is it way to go? If yes ten tell me, good people of StackExchange, how to achieve something like that (grey boxes): !enter image description here
Your looking for custom meta fields, which you can style anyway you want using CSS. < You would either have to write your own functions to accomplish this or use one of the many custom fields plugins, I would recommend the WPAlchemy MetaBox.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "themes, custom field, customization, theme options" }
Posts picking up old Permalinks, how to reset? I've come across a small bug with my yoast breadcrumbs. I've rebuilding a site and have imported some old posts and content and have come across a problem where yoast things the permalinks are still the old ones. I've flushed out all the old categories and tags, etc and have used flush_rewrite_rules() to try and fix it which has resulted in some broken links. Am I missing something in the DB?
There seems to be a bug in the Yoast Plugin, which was fixed by switching on to the NavXT Plugin to do breadcrumbs instead.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, permalinks" }
Display Facebook photo albums and photo comments? I'm looking for a way to pull in photo albums from a Facebook Fan Page into a Wordpress site and have the photos open up in a Lightbox with Facebook comments. I've found a few plugins but nothing quite like what I'm looking for and I haven't seem any with comments. Anyone know whether this is possible? Thanks
I use Facebook Photo Fetcher to share all photos from my facebook fan page to wordpress(organizing by Album is not yet available). It works well except you need to refresh the code after every upload of new photos to facebook fan page, it's not automatic. Unfortunately for me, This plugin doesn't do what I want it to do... which is to display photos from my facebook fan page that my guests are posting (I don't post many photos).
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, plugin recommendation, gallery, facebook" }
modify buddpress adminbar only in admin pages I have modified the buddpress admin bar by creating the following plugin which adds a simple text link to the bar: function bp_adminbar_currentsite_menu() { global $bp; ?> <li> <!-- Insert your link url or relative url, and your link text below --> <a href=" LINK TEXT</a> </li> <?php } // Call The Function Above add_action('bp_adminbar_menus', 'bp_adminbar_currentsite_menu', 999); However, I do NOT want the above link to be shown when logged into the wordpress admin backend (so for example when an admin is editing a post). I thought about just doing a `php_self` check to see if it contained "/wp-admin/" but figured that there has to be a more elegant wordpress/buddypress hook here. How can I get the above code to only show when you are viewing a normal blog page, NOT in the admin area? Thanks
You ca use the conditional tag `is_admin()` to check if you are on the front-end or back-end like this: function bp_adminbar_currentsite_menu() { global $bp; if (!is_admin()){ ?> <li> <!-- Insert your link url or relative url, and your link text below --> <a href=" LINK TEXT</a> </li> <?php } } // Call The Function Above add_action('bp_adminbar_menus', 'bp_adminbar_currentsite_menu', 999);
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugin development, wp admin, admin, buddypress, api" }
Wordpress no longer holding post formatting When creating a new post, by entering either manually or pasting from another document, TinyMCE (the default WordPress editor) does not seem to hold any type of formatting. For instance I create a two paragraph entry. When viewing it on the page it will come through as a single chunk of text within `<div class="entry-content">`. It's forcing me to have to revisit posts quite a bit and manually entering paragraph tags `<p>`. I'm unsure what's causing this issue. Any help would be appreciated.
TinyMCE - at least, as-configured for WordPress - isn't explicitly designed for copying/pasting of text richly formatted in other word processors. That said: how are you pasting? Are you simply copy/pasting (i.e. via CTRL-C, CTRL-V; or else via right-clicking and using contextual menu commands), or are you using the "Paste From Word" button on the TinyMCE toolbar? If you're not using the "Paste From Word" button, please give it a try: 1) On the TinyMCE toolbar, click the "Kitchen Sink" button (last button on the right, on the top row of buttons) 2) Additional rows of buttons will appear 3) On the second row of buttons, click the "Paste From Word" button (the icon is a clipboard with a "Word" icon, "W") EDIT: Are you removing the wpautop() filter? Look for something like this in functions.php: remove_filter( 'the_content', 'wpautop' ); That would definitely cause the line-break issue you're seeing.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "tinymce, formatting" }
Premium theme licensing of php called through AJAX So, I've read through this question about licensing of PHP code under the GPL v2. As well as the compromise of the Thesis theme developer, as far as licensing all PHP under the GPL, but copyrighting js, css, images, etc. My question is does **ALL** php have to be GPL? Consider this scenario: > * the php that generates the wp content/layout is under GPL > * the JS is copyrighted (similar to the question linked above) > * the JS makes AJAX requests to php code that generates certain data > * this data-generating php code uses it's own datalayer (not wordpress's) and uses no wordpress code. > Can the data-generating php (separated into a different folder within the theme) be licensed other than GPL?
The data generating PHP, if it truly stands alone and doesn't use any WordPress code or WordPress' data layer, can be licensed as a standalone library. You can use any license you want here without any problems. The only issues come when you start _distributing_ your code. If you want your theme hosted in the theme repository on WordPress.org, it _must_ be GPL-compatible. That means you have to use either GPL or a more permissible license on your extra library ... If you're distributing things yourself, you just have to make a very clear distinction between the parts of the theme that are GPL and the parts that aren't. But since you'll be bundling a part that's _not_ GPL, you can't distribute the entire package as GPL. So no, all PHP does not have to be GPL unless you're distributing the entire package under the terms of the GPL.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "theme development" }
Installed Wordpress.com Stats with api key and forgot key. How can I register w/ new key? I tried deleting the plugin, reinstalling, and entering a new api key. However, I get this message: > The owner of that API Key (username) is not on the access list for this blog (blog id). Stats was installed using a different API key. Is there anyway I can install the Wordpress.com Stats plugin with a new api key?
Actually, you should be using the JetPack plugin now, not the stats plugin. Automattic (the team behind WordPress.com) have begun bundling their stats system with a few other features (social network sharing, LaTeX support, to name a couple) and aren't updating the older systems any more. JetPack will use oAuth to connect to your WordPress.com account and will automatically select the right blog. If it doesn't, you should contact their support team directly to ask for help.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins" }
adding images to wordpress pagination? I'm working with a blank theme and my nav.php looks like this <div class="navigation"> <div class="next-posts" style="float: left;"><?php next_posts_link('&laquo; Older Entries') ?></div> <div class="prev-posts" style="float: right;"><?php previous_posts_link('Newer Entries &raquo;') ?></div> My question is, how do I change the text links into image links?
Maybe my (edu) plugin can help you understanding the ways that are possible to display pagination a little better. I updated it after reading your Q. You can now more easily style your links. Just add your buttons as background-images to the stylesheet.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "images, pagination, links" }
Creating mulitple loops in a sub-category page I have a main page that consists of 7 categories being output by wp_list_categories, each li specifically includes one ID. These categories are directed to a category-page.php specifically built for each category. Now, each category has sub categories. So on each of the category pages, I want to build out custom queries for each sub category. Example: the Weightloss category on the main page, links to the category-weightloss.php page. Within Weightloss, there are six sub categories. What is the best way, to create six different queries, in seperate div's, so I can style them? I have looked over WP_Query, but I am not sure of the best, and most appropriate, way to do this.
I figured this out on my own. I use the code below and duplicated it as many times as I needed without any issues so far. If anyone thinks this is incorrect than please comment. I was not using the main loop anywhere else on this page and used WP_Query. <ul class="subcats-list"> <?php $weightloss = new WP_Query(); $weightloss->query('showposts=5'); while ($weightloss->have_posts()) : $weightloss->the_post(); ?> <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li> <?php endwhile; ?> </ul><!-- subcat -->
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "loop" }
How can I selectively print scripts to the footer of certain admin pages? I'm using `admin_footer-{$hook_suffix}` to selectively print scripts on the new post page and comments page. This hook is depreciated in 3.1. I see there's an `admin_print_scripts-{$hook_suffix}` but this does not print to the footer, rather to the header before any jQuery or other stuff is loaded. How can I selectively print scripts to the footer of certain admin pages?
There's an `in_footer` parameter that you can pass to wp_enqueue_scripts - does that work? I would hook to `admin_enqueue_scripts`, check the $page for location, and enqueue your script there, with 'in_footer' as true. Example: add_action( 'admin_enqueue_scripts', 'enqueue_my_script' ); function enqueue_my_script( $page ) { if ($page !== 'edit.php') return; wp_enqueue_script( 'my-script', ' null, null, true ); }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "scripts, footer" }
List categories of a post hierarchically? Let's say I got the following categories: Style | + Shoes + Pants If I make a post and put it in the Style and Shoes category, it will list them alphabetically instead of hierarchically. So it would list it as Shoes, Style instead of Styles, Shoes. How can I do this? I tried using "the_category('> ', 'multiple')" but that outputs "Style, Shoes, Style" Thanks!
You could fetch the post categories, then pass them into `wp_list_categories` to take care of displaying them hierarchally. Something like.. wp_list_categories( array( 'include' => array_keys( get_the_terms( $post->ID, 'category' ) ), 'title_li' => '' ) ); Hope that helps.. :)
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "theme development, categories, themes, loop" }
get_posts from post x(offset=>x) to end How can i get the posts using get_posts from let's say post 10 and beyond?So if i have 200 posts i will get from post 10 to post 200(190 posts)? Because as i see if i use <?php $args = array( 'numberposts' => -1, 'offset' => 10 ); ?> i just get all the posts Cheers
It's strange, you'd have thought if you disable paging and grab all posts, that you could naturally set an offset to, eg. array( 'nopaging' => true, 'offset' => 10 ) or array( 'posts_per_page' => -1, 'offset' => 10 ) or array( 'numberposts' => -1, 'offset' => 10 ) This unfortunately doesn't appear to work(bug / oversight in core i'd guess), however the following works, which i'd agree is not perfect, but will work. array( 'posts_per_page' => 100000, 'offset' => 10 ) Just use a really high number, and it'll work around the issue of the `offset` not being respected when paging is disabled.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "get posts" }
I have two problems ( SEO ) how are you ? In my website I want to make the author's page and category(slug of it is country) to be in google reslut .. like this : < , but when I search in google : site:rehlat-world.com , I didn't find authors page. how can include authors page in google result , this is my robort and this is my sitemap note: I change the slug of author ( < from author to profile ( < ) .. how can include author page in google result ? ALSO , when I search in google (site:rehlat-world.com) some of posts repeated like this : < < same reslut but change in the last of like "?replaytocom=37" WHY?
The problem is that your author pages are marked with the noindex tag, look at the page source: It must be a plugin that is doing that, that is not the default setting. If you don't want the duplicate pages, try a plugin like Yoast WordPress SEO that let you add Nofollow to comment links.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "author, seo, google search" }
new post-type how do i retain the plugins on my sidebar? I created a new post-type following this technique: ( After creating a a new post-type some of the feature of the a regular post also disappeared. I installed a plugin (SEO Pressor) that helps my seo on creating a new post. That plugin can be seen in the sidebar when you create a new post, Together with "Publish", "Categories" etc.. . currently the new post-type only contains the "Publish" and "Attributes" block. Any idea how I can call those plugin to my new post-type? Thanks!
The plugin would need to support custom post types. You might be able to ask the plugin developer to add that. The custom post type API's are fairly new and still don't have widespread support. You can see that they are adding the meta boxes only for posts and pages: add_meta_box( 'WPPostsRateKeys-Keyword', 'SEOPressor Keyword', array(&$this,'add_box_in_post_form'), 'post', 'normal', 'high' ); add_meta_box( 'WPPostsRateKeys-Keyword', 'SEOPressor Keyword', array(&$this,'add_box_in_post_form'), 'page', 'normal', 'high' ); add_meta_box( 'seo_pressor_post_suggestions', 'SEOPressor Score', array(&$this, 'show_score_box'), 'page', 'side', 'high' ); add_meta_box( 'seo_pressor_post_suggestions', 'SEOPressor Score', array(&$this, 'show_score_box'), 'post', 'side', 'high' ); But without knowing how much they rely on the different post types it's hard to say how easy it would be to add those meta boxes to custom post types.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, functions" }
How to disable 3.1 "Admin Bar" via script for the admin user? Every time I create a new site under 3.1, my first trip is to the Users > Admin User profile page to uncheck the "admin bar" checkbox. I'd like to place a script in my theme's functions.php to do this automatically. Anyone know what that would be?
You could use a function inside your theme's functions file to selectively disable it for specific users. function disable_bar_for_user( $ids ) { if( !is_user_logged_in() ) return; global $current_user; if( is_numeric( $ids ) ) $ids = (array) $ids; if( !in_array( $current_user->data->ID, $ids ) ) return; add_filter( 'show_admin_bar', '__return_false', 9 ); } Then call it for the user or users you want to disable the bar for.. **Single user:** disable_bar_for_user(1); **Multiple users:** disable_bar_for_user(array(1,2,3)); If you want to just turn it off altogether, then the following should do it(instead of the function). add_filter( 'show_admin_bar', '__return_false', 9 ); Hope that helps.. :)
stackexchange-wordpress
{ "answer_score": 5, "question_score": 3, "tags": "theme development, php, customization, admin bar" }
What exactly does "Posts page" do in WordPress? Hay, I'm making a WordPress template, and i have 4 main pages. HOME BLOG CONTACT ABOUT US As you can see "Blog" is a page (i need it to display when i call wp_list_pages()), but how do i edit this blog page? I assigned the "Blog" page a custom temeplate (called blog.php), but when "Blog" is set as the "Post page" in the Reading section of the WordPress admin, the page fails to render the template. How do i edit this "Blog" page?
Setting page to be "posts page" changes its template hierarchy to follow home page rules. So your custom template is ignored and it looks for `home.php` or `index.php`, which might or might not be the reason it fails to render.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 4, "tags": "php, html, templates" }
Troubleshooting fetch_feed and SimplePie I've got a very basic solution using `fetch_feed()` and SimplePie to pull in RSS items which is working on my localhost, but for some reason `is_wp_error()` persists as `true` on the live server. Is there anyway for me to get specific output about the nature of the error so as to work towards a solution on the live server? <?php include_once(ABSPATH . WPINC . '/feed.php'); $rss = fetch_feed( '[rss feed removed from example]' ); if (!is_wp_error( $rss ) ) : $maxitems = $rss->get_item_quantity(5); $rss_items = $rss->get_items(0, $maxitems); $isc = ' endif; ?> <ul class="featured-products"> <?php if ( $maxitems == 0) : ?> <li>No items.</li> <?php else : ?> <?php foreach ( $rss_items as $item ) : $image = $item->get_item_tags( $isc, 'thumb'); ?> <li>...</li> <?php endforeach; ?> <?php endif; ?> </ul>
add this to your feed $rss = fetch_feed( $url ); if ( is_wp_error( $rss ) ) { echo $rss->get_error_message(); <---this } else { // do your stuff here } I would also suggest installing the debug toolbar extensions, like "debug-bar-extender".
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "feed, simplepie, troubleshooting" }
Self-Hosted Blog on Google Search I have a self-hosted blog, (Code Repo - Code Snippets) but for some reason when I search for it on google, it doesn't come up in the results. I posted an entry about 4 days ago, and by now I would have expected it come up in the results. When I search for things on my normal site (same domain), they do come up, its just things inside the blog that don't seem to be included. In the past, I have only had blogs hosted on wordpress.com and they have always automatically come up. What can I do to fix this? Thank you!
Googling "site: seems to show that you blog is getting indexed and quick check doesn't find any settings prohibitive to indexing set. Other than latter there isn't really much that can be done, it's up to Google how it indexes and serves your site in results.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "google search" }
custom login form redirect problem I'm facing a strange problem here with this custom login form: <form name="loginformfooter" class="loginform" id="loginformfooter" action="<?php bloginfo('url'); ?>/wp-login.php" method="post"> <input type="text" name="log" id="user_login" class="input" tabindex="1" /> <input type="password" name="pwd" id="user_pass" class="input" tabindex="2" /> <input type="submit" name="wp-submit" id="wp-submit" value="Login" /> <input type="hidden" name="redirect_to" value=" . $_SERVER['REQUEST_URI'];?>" /> <input type="hidden" name="testcookie" value="1" /> </form> The most of the times it redirect me to the correct page, but few other times, especially at first login, it redirects me to the admin page. I'm not able to determine precisely when the problem occours. Does anyone found a problem like that? Or is there a better solution to get the same result? Thanks!
### Php Short tags are a "no-no" You shouldn't use short php like this: `value=" ### Where does it come from? Different servers, different php.ini files. You simply ran into the problem that `short_open_tag = Off` is set. Not all servers have this set to true per default. Further more not all hosts allow editing the php.ini file - for good reasons. ### Check ini settings Try the follwing inside your code: `<?php echo 'short open tag: ' . ini_get('short_open_tag'); ?>`. ### Set ini settings If you see that it's off you can try turning it on in your php.ini file using.. `<?php ini_set('short_open_tag', 'ON'); ?>`. ### Alternatively (per t31os's suggestion) If the login page is the first page on your site you request, there is no request URI to pass along, so naturally a redirect won't happen because there's no request URI to send you to.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "redirect, login" }
Why is the admin bar appearing (on certain pages) for non logged-in users? The admin bar is appearing for non logged-in users on one of my sites, but only for two specific pages (/work and /contact, for what it's worth). Has anyone heard of this happening before? It appears as though one of the site's users is logged in (their username is displayed), but clicking any links on the admin bar lead to the login page. If I click Log Out under that users name in the admin bar, I get a prompt to ensure I want to logout, then a redirect to /wp-login.php. However, upon returning to /work or /contact, the admin bar still appears.
Since I think that mis-identifying all users not-logged in is extremely unlikely, my line of thought is that wrong non-public version of page was cached for some reason.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "admin bar" }
List all sidebar names? I'm listing all sidebars like that: global $wp_registered_sidebars; echo '<pre>'; print_r($wp_registered_sidebars); echo '</pre>' So I'm getting something like: Array ( [sidebar-1] => Array ( [name] => Sidebar #1 [id] => sidebar-1 [description] => Sidebar number 1 [before_widget] => [after_widget] => [before_title] => [after_title] => ) (...) ) But I'd love to display them as a select list, like: <select> <option value ="SIDEBAR-ID">SIDEBAR-NAME/option> <option value ="SIDEBAR-ID">SIDEBAR-NAME/option> (...) </select> Wordpress Codex isn't helpful at all. Thank you!
### Loop through the global: <select> <?php foreach ( $GLOBALS['wp_registered_sidebars'] as $sidebar ) { ?> <option value="<?php echo ucwords( $sidebar['id'] ); ?>"> <?php echo ucwords( $sidebar['name'] ); ?> </option> <?php } ?> </select> Note: The `ucwords()` function is only there to display it exactly as you asked. Not sure if you really want that. * * * ### How to access global arrays & objects: _Anyway:_ Your Q mostly is about how to access arrays. I wrote a Q about that (for further explanation). Please take a look over here.
stackexchange-wordpress
{ "answer_score": 29, "question_score": 16, "tags": "plugins, plugin development, sidebar, register sidebar" }
Redirect /home to home.php In my WP admin's "Pages" section is a page called "Home" with a URL of /home. This page's content gets called by my index.php file. My problem is the /home page is coming up in search results, or someone could type in /home. Is it possible to redirect /home to index.php (or just "/")?
Change your index.php file back to normal, then set that home page as the front page instead. Then the /home will redirect to / as it should.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "redirect, pages, homepage" }
How to Get All Posts with any post status? I am creating a front end dashboard where I need to show all the posts by the current user. So, I need to show posts in all states, mainly `published`, `trashed` and the `pending`. I am now using a simple query but it is returning only the published posts. $query = array( 'post_type' => 'my-post-type', 'post_author' => $current_user->ID ); query_posts($query); Can anyone help? What else do I need to do?
You can use the post_status parameter: * 'publish' - a published post or page * 'pending' - post is pending review * 'draft' - a post in draft status * 'auto-draft' - a newly created post, with no content * 'future' - a post to publish in the future * 'private' - not visible to users who are not logged in * 'inherit' - a revision. see get_children. * 'trash' - post is in trashbin. added with Version 2.9. I'm not sure that it accepts 'any' so use an array with all of the statuses you want: $args = array( 'post_type' => 'my-post-type', 'post_author' => $current_user->ID, 'post_status' => array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash') ); $query = new WP_Query($args); while ( $query->have_posts() ) : $query->the_post();
stackexchange-wordpress
{ "answer_score": 107, "question_score": 59, "tags": "query posts, wp query, post status" }
Menu capability in Wordpress Is it possible to specify two usergroups (e.g. admins and editors) into the admin menu capability field ? I tried the following but it doesnt work: add_submenu_page( 'my-top-level-handle', 'Page title', 'Sub-menu title', array('administrator', 'editor'), 'my-submenu-handle', 'my_magic_function' ); error message: Warning: Illegal offset type in isset or empty in C:\wamp\www\wordpress\wp-includes\capabilities.php on line 712
Capability parameter of add_submenu_page() function can only take a single capability, so if you are using the built in roles you can select a capability fro the long list that both administrators and editors have any of these (use any of these freely): * moderate_comments * manage_categories * manage_links * unfiltered_html * edit_others_posts * edit_pages * edit_others_pages * edit_published_pages * publish_pages * delete_pages * delete_others_pages * delete_published_pages * delete_others_posts * delete_private_posts * edit_private_posts * read_private_posts * delete_private_pages * edit_private_pages * read_private_pages
stackexchange-wordpress
{ "answer_score": 8, "question_score": 3, "tags": "capabilities, add submenu page" }
How to override WP_DEBUG for Ajax responses? It is highly recommended practice (that I completely agree with) to develop with `WP_DEBUG` enabled. However it is merely inconvenient to see not yet fixed warnings in pages, but in Ajax responses they ruin response completely. I am just starting with Ajax in WP, is there some appropriate hook to suppress errors for Ajax responses only? PS fix everything is not viable option at moment, because it is extremely extensive and complex environment :)
In `wp-config.php`: if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) define( 'WP_DEBUG', false ); else define( 'WP_DEBUG', true );
stackexchange-wordpress
{ "answer_score": 9, "question_score": 4, "tags": "ajax, wp debug" }
Script to remove all inactive widgets? I've been working with widgets a lot lately and have amassed a ton of widgets in the inactive widgets collection. Can someone share a script or plugin that will remove all inactive widgets from the site?
something like: $widgets = get_option('sidebars_widgets'); $widgets['wp_inactive_widgets'] = array(); update_option('sidebars_widgets', $widgets);
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "plugin development, widgets" }
What is a short code? I am new to WordPress and I've seen this term passed around.
"Shortcode" is a user friendly way of inserting various WordPress plugins/scripts into a page without having to know a lot of fancy HTML/JavaScript/PHP in order to make it happen. Take, for example, embedding an mp3 file into a post on a hosted WordPress site. Instead of having to setup the proper code for a flash player or fiddle with some fancy JavaScript, you can use the following shortcode in the editor. You don't even switch to HTML mode... [audio: ...and WordPress does the rest for you. You'll find a lot of plugins for WordPress (such as Contact Form 7 and others) use this convention.
stackexchange-wordpress
{ "answer_score": 8, "question_score": 1, "tags": "shortcode" }
Hide a page in the admin end without a plugin? I'm creating a series of pages with iFrames embedded in them, but it seems the only way to do this within Wordpress (i.e. using the templating system) is to create pages in the admin end and then create individual templates for each of those pages. Is it possible to hide those pages from the admin without a plugin? I see no need for the client to see those pages when they can't edit anything in them. Thanks, osu
you can use `parse_query` filter hook to exclude your pages using post__not_in attribute add_filter( 'parse_query', 'exclude_pages_from_admin' ); function exclude_pages_from_admin($query) { global $pagenow,$post_type; if (is_admin() && $pagenow=='edit.php' && $post_type =='page') { $query->query_vars['post__not_in'] = array('21','22','23'); } } this will exclude pages with the ids of 21,22,23 and to make sure this pages will not be included on the front end using wp_list_pages you can use wp_list_pages_excludes filter hook: add_filter('wp_list_pages_excludes', 'exclude_from_wp_list_pages'); function exclude_from_wp_list_pages($exclude_array){ $exclude_array = $exclude_array + array('21','22','23'); return $exclude_array; }
stackexchange-wordpress
{ "answer_score": 7, "question_score": 3, "tags": "wp admin, customization" }
Check the password of a user I want to keep a check if the user has a particular password, so I have been trying it with `wp_check_password` but the account for which it is checked gets logged out and can't login again till there is a call of `wp_check_password` in the code. Digging into the code, I found out that it sets the password by using the new hash. and moreover if I am using `wp_check_password( 'hello', md5('hello'), 1 );`, it doesn't even check what is inside the database and returns true. Isn't that a bug? Any ideas how can I check the user's password?
~~Your example works correctly. You are checking if password`hello` matches hashed `hello` \- which it naturally does.~~ Hadn't thought it through. Your example causes following issue: 1. You check if `hello` matches md5 of `hello` (instead of hash from user's profile). 2. It does and then WP thinks this is correct, but outdated md5 hash - that must be updated. 3. It re-hashes `hello` and updates user with it, locking him out (since his password is now `hello` instead of whatever it was before). See `wp_authenticate_username_password()` function for extensive example, but basic idea is: $userdata = get_user_by('login', $username); $result = wp_check_password($password, $userdata->user_pass, $userdata->ID);
stackexchange-wordpress
{ "answer_score": 13, "question_score": 5, "tags": "password" }
Hook for plugin to insert into entry-meta pretty simple. I'm creating a plugin and I want to dynamically insert some text that will change every hour into the line that is directly below the title of a post (So filters are no good). It's the `<div class="entry-meta">`. The `<div class="entry-utility">` at the bottom of the post would be good too. I can't seem to find a hook for this and I'm guessing there is none. Right now the solution I have is to hook into "the_content" and place it as a footer, but it looks reaaally bad because it's a small piece of text with an entire line to itself. It would look considerably better if I could insert it into those lines mentioned.
The lines you mention are most likely part of your theme. You will need to either: * figure out which functions/templates output them and if they have hooks to use; * edit theme (create child theme) to add your own function to output what you want.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, hooks, footer, headers" }
Can data from a Custom Field data be used by a shortcode on a per page/post basis? I'm developing a site where better is very quickly becoming the enemy of the good. I would like to make updating as simple for the client as possible by enabling them to populate boilerplate and images text using a shortcode. However, there is one word within the boilerplate text which needs to be unique for each page and must be added by the client. I was thinking of using a specific custom field key and value, as a way of capturing the unique information. Is it possible and reasonable to use custom fields for this purpose within the shortcode? I'm having trouble thinking through the syntax. Is there a better way to do this?
Not sure I understand your specifics, add details if I am off. I assume: 1. Your shortcode inside post's content. 2. You have custom field in that post with value you want. In this case declare in your shortcode function `global $post;` and use `$post->ID` to retrieve custom field.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "custom field, shortcode" }