INSTRUCTION
stringlengths 11
999
| RESPONSE
stringlengths 0
999
| SOURCE
stringlengths 16
38
| METADATA
dict |
---|---|---|---|
Change permalinks for posts but not custom post type?
I want my permalink for my standard posts to be www.mywebsite.com/photoblog/name-of-post
So I've written the custom structure as: /photoblog/%postname%/
However, my custom post type 'projects' permalinks now displays as www.mywebsite.com/projects/photoblog/name-of-post
How can I fix this so it only displays 'photoblog' in the standard post type? | I added with_front='false' to the slug rewrite for the custom post type | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "custom post types, posts, permalinks"
} |
oEmbed not recognising Vimeo URLs
I am trying to embed a Vimeo video into a post. I am inserting the URL into the page like so.
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
http//vimeo.com/1234
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
It is outputted as the plain text URL. I have tried it with a youtube link and it worked perfectly. I have also tried wrapping it in the `[embed]` shortcode but that just wrapped it in anchor tags.
Any suggestions would be much appreciated, thanks. | Looking into WordPress Core vimeo is registered like so:
'# => array( ' true ),
But looking at vimeo API for oEmbed they show their URL without the `www.` so what you need to do is register vimeo oEmbed correctly:
add_action( 'init', 'add_vimeo_oembed_correctly' );
function add_vimeo_oembed_correctly()
{
wp_oembed_add_provider(
'#
'
true
);
}
You can place this in your theme functions file or place in a plugin.
You may need to revisit posts that have Vimeo embeds and save again after putting this fix in. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "oembed"
} |
Advanced Custom Fields Plugin - Conflict with Custom Post Type Default Editor
Advanced custom fields(2.1.4) plugin disables the wordpress default editor for custom post types. How can I fix this. | I'm using Advanced Custom Fields (3.1.5) and attaching it to a custom post type. I was startled when adjusting some values with my advanced fields that the editor for my custom post type disappeared.
I solved the problem very simply: On the Edit Field Group page, go to the bottom of the Options section and make sure 'Editor' is enabled in the 'show on page' options. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "custom post types"
} |
Set default image sizes in WordPress to hard crop
How do I set the medium and large images sizes in WP to hard crop?
In my theme I can set the thumbnail size to hard crop using this:
add_theme_support('post-thumbnails');
set_post_thumbnail_size( 96, 96, true );
But I can see no way to make the medium and large images to hard crop.
Is there possibly a way to remove the medium and large sizes and re-add them using:
add_image_size( 'medium', $width, $height, true );
add_image_size( 'large', $width, $height, true ); | You can over write the default like this:
add_image_size( 'medium', 200, 200, true ); | stackexchange-wordpress | {
"answer_score": 21,
"question_score": 22,
"tags": "images"
} |
Buy now button and thankyou page for my website?
I want to activate Paypal 'Buy Now' button for my products. After purchasing product it needs redirection to thank you page. How to do this via a plugin?
Is there any plugin available for this task? Please recommend a plugin or an easy way to achieve this.
Thank you. | For wordpress plugins you can see the below links
1. <
2. <
3. <
* * *
**Check this plugin link it might work in your case and its tested in wordpress 3.1 its working fine.**
url: <
To customize the paypal payment and thankyou message you can code as per your requirement but u need to know the paypal api how it interact.
**To know about paypal html variable see the link:**
url:
**To know more about paypal payment form see the good tutorial on net tuts+**
url: < | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "plugin recommendation, paypal"
} |
List users by last name in WP_User_Query
How can I list users by last name ASC when using WP_User_Query?
There is an orderby parameter but looking in core it doesn't accept ordering my user meta. Anyone know how to extend WP to allow this ordering by last name? | There is a **better way to do this as of Wordpress version 3.7.** Use the Wordpress property meta_key to select the last name property and then orderby => meta_value with an ascending order.
<?php
$args = array(
'meta_key' => 'last_name',
'orderby' => 'meta_value',
'order' => 'ASC'
);
$user_query = new WP_User_Query( $args );
if ( ! empty( $user_query->results ) ) {
foreach ( $user_query->results as $author ) {
// Line below display the author data.
// Use print_r($author); to display the complete author object.
?>
<a href="<?php echo get_author_posts_url($author->ID); ?>" class="author"><?php echo get_avatar($author->ID, 96); ?><?php echo $author->display_name; ?></a>
<?php
}
}
?> | stackexchange-wordpress | {
"answer_score": 12,
"question_score": 8,
"tags": "users, wp user query"
} |
Picture inserted in the post not showing in "Gallery"
I have some posts in which I inserted the picture manually (before migrating to Worpdress)
<img src=" border="0" alt="" />
I want to use those pictures as "featured image", but they don't appear in the post Gallery. What is the best way to "import" them, knowing that they already are on my server ?
Thanks | Found a solution - using the plugin "Add from server", I can re-import the pictures which I attached to the posts when the blog was powered by Dotclear. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "post thumbnails, gallery"
} |
Disable redirect canonical
I am trying to prevent `index.php` from redirecting to a file `index.html` which I also have in the home directory. I want `index.html` to remain there for a few days until the WordPress site is finished, being the page that visitors will see, and I'd access the new installation by adding `index.php` to the url; but WordPress redirects `index.php` to `index.html` meaning that I can only view the pages and posts and not the home page. I have tried putting `remove_filter('template_redirect', 'redirect_canonical');` into the `functions.php` file but it doesn't work. | Found the problem - you have to access index.php/ not just index.php | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "theme development, redirect"
} |
custom post type not getting archived?
I'm used the plugin More Types to create a custom post type (News). I'm also using the plugin Smart Archives Reloaded to have an archive of my custom post type.
The problem is when i click on a month which takes me to .com/2011/10 i just get a page not found.
I've also added the wordpress archive widget to the sidebar just to see if it shows any of my posts, which it doesn't. If i post a normal post (one that comes built in with wordpress) that show's in the archive widget and also clicking on the month shows a page with that post on it instead of a page not found.
In the More Types plugin i've set the post to archives yes.
Is it possible the posts aren't getting archived and that's why i'm getting a page not found, or is this two separate issues?
Thanks | I've used a plugin called collapsing archives and it appears to be working with that. Maybe it was an issue with smart archives not working with custom post types, not really sure. It's working now though. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "custom post types, custom post type archives"
} |
post thumbnail: increase dimension if smaller than... Possible?
I need thumbnails of minimum width: 400px.
I would like that if the user uploads an image that is, say, 380px wide, Wordpress creates a 400px-wide version.
Is that possible? | No, its not. But you can set up a css rule like min-width:"400px" for the thumbnails | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "post thumbnails, images"
} |
upgrade from WPMU 2.9.2 to WP 3.2.1
I am running WPMU 2.9.2 and want to update to WP 3.2.1.
As I understand it, WP 3 took in WPMU. I imagine that involved some big changes to the implementation of WPMU. What steps do I need to take to perform the upgrade?
Thank you.
Pat | The codex has some very detailed advice: Upgrading_WPMU. Make sure to test it on a safe copy of the real site. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "multisite"
} |
Add class to WordPress admin bar?
How can I to add a wrapper class to the WordPress admin bar?
I would like to center the contents to the same width as my theme. | There isn't a filter/wrapper for the admin bar CSS that you can plug into , the function is simply
function wp_admin_bar_header() { ?>
<style type="text/css" media="print">#wpadminbar { display:none; }</style>
You can over ride the CSS using `!important` or use jQuery to prepend a class/id to the bar.
Something like:
jQuery("<div id='custom-width'></div>").prependTo("#wpadminbar"); | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 2,
"tags": "admin bar"
} |
Select Category as Page Parent
I've got a custom post type called Products and when i go to select page parent i only get other pages of the same post type.
Is it possible to select a category as a parent for the page?
The reason i'm asking is i have a plugin that lets me automatically add child pages to a menu under the parent. If i can somehow be able to set a category as a parent to the custom post type it should automatically add it to the menu.
Here's the plugin i'm using. < | I didn't need to set a category as a page parent, i found this which did exactly what i needed. It shows a menu of categories and subcategories as well as their posts. < | stackexchange-wordpress | {
"answer_score": -1,
"question_score": 0,
"tags": "custom post types, categories"
} |
Can I create my own "Recent Posts" widget or customize the existing one?
I'd like to enable the Recent posts widget with the ability to show a "View All" link when there are more posts than I've currently got the widget set to show.
I'd also like to be able to exclude certain categories or posts from it.
Is it possible to do either via my theme's functions.php?
(1) Customize the existing widget or (2) Create a copy of it that I can customize? | It's usually best to copy the existing one, name it something unique, and then add your own functionality.
Copy the `WP_Widget_Recent_Posts` class from wp-includes/class-wp-widget-recent-posts.php into your functions.php (or, preferably, another file in your theme devoted just to widgets) and rename to something else, like `My_Widget_Recent_Posts`
Add your functionality in there.
Don't forget to call `register_widget('My_Widget_Recent_Posts')` as part of the `init` phase as well. | stackexchange-wordpress | {
"answer_score": 22,
"question_score": 14,
"tags": "theme development, widgets"
} |
Shortcode Variations?
The function below creates a button when used like so [btn]Button Text[/btn]
function btn($atts, $content = null) {
extract(shortcode_atts(array('link' => '#'), $atts));
return '<a class="btn" href="'.$link.'"><span>' . do_shortcode($content) . '</span></a>';
}
I'd like to be able to add two variations to this, color and size which would allow the button to be called with variations, like this: `[button color="teal" size="large"]Button Text[/button]`
But I can't figure out how to do this. Anybody have a code? | function btn($atts, $content = null) {
extract(shortcode_atts(array('link' => '#', 'color' => 'teal' , 'size' => 'large'), $atts));
return '<a class="btn '.$size.'" href="'.$link.'" style="background:'.$color.';"><span>' . do_shortcode($content) . '</span></a>';
}
With that function you get by default color teal and size large. I suppose that for size you are using classess and for color just background. If not the case just leave a space and added it on the class attribute. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "functions, shortcode"
} |
How to determine if I'm on the first page of pagination?
How do I determine if I'm on the very first page of pagination? I'm using WP_Pagenavi. I want to run a function only on the first page of the pagination. I checked the query_var 'paged', it's set to 0 on this page, and then 2, 3 and so on in the later pages (1 is missing!)... Anyone knows a clean solution?
Thanks. | // get current page we are on. If not set we can assume we are on page 1.
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
// are we on page one?
if(1 == $paged) {
//true
} | stackexchange-wordpress | {
"answer_score": 31,
"question_score": 26,
"tags": "pagination, paged, plugin wp pagenavi"
} |
How can I make different page templates for one category?
I need this for menu "red car", "blue car", "green car".
Information is retrieving from a single category (cars). But the output on pages depending on the values in the metaboxes (colors). On the page with blue cars shouldn't be a green cars.
Cars and colors for illustrative purposes only.
How can I do this? | I did it with $_REQUEST help. This is not very pretty solution because of ugly url, but it works.
<
Something like:
if ( $_REQUEST['key'] == 'value' ) {
$additional_args = array(
'meta_key'=>'key',
'meta_value'=>'value'
);
$args = $args + $additional_args;
}
$query = new WP_Query ( $args ); | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "page template, templates"
} |
has_archive for default post type
So I have several CPTs set up but I want to have all my default posts listed under /blog.
I was hoping I could somehow enable has_archive for the default post type but I have yet to succeed.
Any ideas?
add_action( 'init', 'enhance_post' );
function enhance_post( ) {
global $wp_post_types;
$wp_post_types['post']->has_archive = true;
$wp_post_types['post']->rewrite = array(
'slug' => 'blog',
'with_front' => 0,
'pages' => 1,
);
}
(the above doesn't seem to work) | You can change front page and designate another as blog via _Reading_ settings.
See Creating a Static Front Page in Codex. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "custom post types, custom post type archives"
} |
Header Link function not working. Problem with bloginfo()
I'm writing a function to make all of my header images link to their respective home pages. I wrote this function:
function get_category_location(){
$header = get_category_header();
$home = bloginfo('url');
if ($header == 'wth') {
$location = $home . "/wth/" ;
}
else if ($header == 'campus' || $header == 'tech') {
$location = get_category_link();
}
else {$location = $home;}
return $location;
}
so when you click a header in the wth section of our site $header should equal 'wth' and $home should equal ' and so location should be set to '
as far as I can tell $header and $home are correct. | you are storing the value into a variable you need to use
get_bloginfo('url')
< | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "categories, headers, bloginfo"
} |
url rewriting for most recent post
I'd like to set up my WP so that urls ending in `/last` would return the most recent post in that set of posts. For example, `/last` returns the most recent post of any type, `archives/category/trivia/last` would return the most recent post categorized as trivia, and `archives/LoomSong/last` would return the most recent custom post of type='LoomSong'.
I think I need to add rewrite rules, but I'm very unsure of what the regex should be. So far this is what I have:
add_action( 'init', 'ASHmostrecent_init' );
function ASHmostrecent_init(){
add_rewrite_rule( 'last/?$', 'WHAT DO I PUT HERE?');
}
add_filter( 'query_vars', 'ASHmostrecent_query_vars' );
function ASHmostrecent_query_vars( $query_vars ){
$query_vars[] = 'ASHmostrecent_filter';
return $query_vars;
} | add_action( 'init', 'ASHmostrecent_init' );
function ASHmostrecent_init(){
add_rewrite_rule( 'last/?$', 'index.php?post_type=post&posts_per_page=1');
}
A query already pulls up posts starting from the latest to the oldest, so all you have to do is limit what's returned by one. `posts_per_page` does this; limiting by one will give you the latest post. Edit the `post_type` accordingly. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 2,
"tags": "url rewriting"
} |
Retrieving images from a NextGEN gallery
I'm not sure if this is possible but after extensive searching I can't find an answer.
What I want to do is to get all images from a NextGEN gallery so I can display them in a custom slideshow within a page/post.
Is it possible to load them into an array or edit the HTML in some way?
Any help is greatly appreciated! | For anyone interested I found a solution to what I wanted.
You simply need to create a custom template
Then I accessed the images like this:
<?php foreach ($images as $image) : ?>
<?php echo do_shortcode('[singlepic id="' . $image->pid . '"]'); ?>
<?php endforeach; ?> | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 2,
"tags": "images, plugin nextgen gallery"
} |
Custom Database Table and foreach
I have just created a custom database table and would now like to output every inserted row from it into a predefined format using a foreach statement.
Some guidance in this matter would be great.
Thanks, Ashley | Thanks to Rutwick Gangurde, I found out how to do it.
<?php
$mylistitems = $wpdb->get_results("SELECT * FROM wp_mytable");
foreach ( $mylistitems as $mylistitem )
{
echo $currency->somefield;
}
?> | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "customization, database, php, table"
} |
Should HTML output be passed through esc_html() AND wp_kses()?
I'm confused about the different uses of `esc_html()` and `wp_kses()`. I understand that `esc_html()` converts special characters to their HTML entity, and that `wp_kses()` removes unwanted tags (e.g., `<script>`), but I'm not sure in what contexts they should be used together or separately.
If I run some untrusted HTML through `esc_html()`, then any JavaScript will be displayed in plain text rather than being rendered by the browser, so it is safe at that point, correct? The only reason to also run it through `wp_kses()` would be to avoid having the raw script displayed?
Basically, `esc_html()` makes it safe, and `wp_kses()` makes it pretty. Is that correct? | The general rule, at least as espoused by Mark Jaquith, is **sanitize on input, escape on output** (the corollary to this rule being **sanitize early, escape late** ).
So: use sanitization filters (such as the `kses()` family) when _storing untrusted data in the database_ , and use escaping filters (i.e. the `esc_*()` family) when _outputting untrusted data in the template_. | stackexchange-wordpress | {
"answer_score": 18,
"question_score": 12,
"tags": "escaping, sanitization"
} |
Options for Wiki WordPress
I would like to know my options for how best to use WordPress as a wiki. I tried Media Wiki, but the sheer amount of changes I need to make to code to make even trivial changes turned me off. Way off.
Googling doesn't reveal much. What are the best options for using WP as a wiki? (This can be a community question discussing various options.)
In particular, I would like something that addresses:
* Links to non-existing pages actually link to a "create new page" page
* Editing pages without going through /wp-admin/ (i.e. the back-end)
* Searching/listing existing pages when linking (i.e. linking by title, not by URL)
What are my options? | Wordpress CMS is for blogging you can do this with it but can make something similar like this with your own logics but i recommend you to use other CMS there are many CMS for wiki also check this top 5.
MediaWiki
MoinMoin
PhpWiki
OddMuseWiki
TikiWiki | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 2,
"tags": "wiki"
} |
Is it possible to know which category page the post was linked from?
For example, I have a post that's filed under category 1 and category 2. When someone clicks on it from category 2, I want to know the slug for category 2. If it links from the category 1 page, I want to know the category 1 slug.
Is this even possible? | As anything that has to do with stats this is really an analytics task and as such not something that WP does natively.
You options are:
* installing (if not already) some kind of analytics solution and getting data from it
* add code to that post that will track referers (I won't really recommend this since it comes with performance issues and poor caching compatibility) | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "categories"
} |
Plugin to Link Posts by Title
I'm looking for a plugin that will allow me to link to posts by title. That is, when I click the link icon in the editor (or some other icon), instead of entering a URL, I get a drop-down of posts to link. I select one, press okay, and tada! Link is done.
I also expect that the link looks at the ID; so if I change the target page's title, post-slug, or any other features that may be in the permalink, the link is "smart enough" to still link the correct page.
Does anything like this exist out there? I couldn't find anything. | SEO Smart Links does an amazing job for this. It provided exactly what I wanted.
Originally, I used RB Internal Links. It only works through the visual editor, though. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "plugin recommendation, links"
} |
w3 total cache - Object Caching 2165/2469 objects?
Site is: <
WordPress 3.2.1 MS, buddypress,bbpress installed. wp_options have 333 records. But Object Caching 2165/2469 objects? Why 2000+ ?
Debug: < lots of notoptions:options , alloptions:options ? whats those? | Simply put - not everything in object cache is an option. Many other things, such as fetching posts or results of resource-intensive function calls, are also cached in there.
I am not sure about meaning of that naming scheme, but according to plugin's author that seems to be normal operation. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "cache, plugin w3 total cache, oop"
} |
Redirect in an Admin page
I have a menu item I created called 'View Certificates' and a sub menu item called 'Add Certificates'. The Add Certificates page is just a file upload page. After the file uploads successfully, I want it to redirect back to the 'View Certificates' page.
All my code is in the functions.php file. How do I go about doing this redirect? | You can use wp_redirect
<?php
$url='something.com';
wp_redirect($url);
exit;
?> | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "admin, redirect"
} |
how to publish a feed of posts with a certain custom field value?
In addition to the normal feed that wordpress produces, i need to publish an additional feed of posts that have a certain custom field value.
I'm a bit lost on where to start. Any tip? | Something like this will add a /feed/special to your site.
add_feed('special','do_special_feed');
function do_special_feed() {
query_posts(array(
'meta_key' => 'key',
'meta_value' => 'value',
));
do_feed_rss2(false);
}
After putting it in a plugin or your theme's functions.php or what have you, you'll need to visit the Settings->Permalinks page at least once and save the settings, to get it to rebuild the permalink rules. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "feed"
} |
How do I urlencode() the blog description?
I have a series of share buttons, each one using a short URL (using Ozh's Yourls plugin) and a page title (as found on urlencoding of the_title() doesn't work?) and some require a description. How do I put the blog description, encoded correctly, into my URL? | echo urlencode(get_bloginfo('description')); | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "description"
} |
Twenty Eleven: Home Page, View full post of most recent post & Summary of the rest
I am using the Twenty Eleven theme and need to show the full content of the latest post and then show the rest as summary. I'm looking for instructions/help on how to display, on the home page, the full post of the most recent article and then just the summary of the older the posts.
For Example (Post #5 being the newest & Post #1 being the oldest):
Post #5 (Full Article)
Post #4 (Summary)
Post #3 (Summary)
Post #2 (Summary)
Post #1 (Summary) <\-- Next
Any ideas? Please help! | after creating a child theme for Twenty Eleven, copy **_content.php_** from the Twenty Eleven theme into your child theme to edit it;
find (line 35):
<?php if ( is_search() ) : // Only display Excerpts for Search ?>
change to:
<?php if ( is_search() || is_paged() || $wp_query->current_post > 0 ) : // Only display Excerpts for Search, paginated pages, or any other then the first post ?>
then find this section:
<div class="entry-content">
<?php the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentyeleven' ) ); ?>
and change to:
<div class="entry-content">
<?php global $more; if( $wp_query->current_post == 0 && !is_paged() ) $more = 1; ?>
<?php the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentyeleven' ) ); ?> | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "excerpt, homepage, theme twenty eleven"
} |
How to set permalink structure via functions.php
I'm setting up a Wordpress Network and wanted all new sites to have the same permalink structure (i.e. "/%year%/%monthnum%/%postname%/"). I'm wondering if this is possible to do via hooks or hacks in functions.php, without having to rely on users to choose that structure. | You can set the permalink structure by calling on the `set_permalink_structure()` method of the global `$wp_rewrite` object.
add_action( 'init', function() {
global $wp_rewrite;
$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
} );
Here's a PHP < 5.3 version of the code in case you're getting errors.
function reset_permalinks() {
global $wp_rewrite;
$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
}
add_action( 'init', 'reset_permalinks' ); | stackexchange-wordpress | {
"answer_score": 17,
"question_score": 10,
"tags": "theme development, permalinks, multisite"
} |
What is the best way to add an advanced / intermediate / beginner tag to a post
Suppose you have a WordPress blog that you are using to produce tutorials, and that you would like to split up your posts according to skill level (i.e. beginner, intermediate, advanced) depending on how technical/difficult/advanced the tutorial is. Furthermore, the blog in questions spans several categories, so using these might be inappropriate.
So what's the best way? Using custom field?, tags?, post-type? or even sub-categories? I'm assuming that it shall never be required to retrieve all 'beginner' posts from all categories, though this flexibility would be a bonus. | Use a 'difficulty' custom taxonomy. The only thing is that you'll have to roll your own metabox that allows you to choose a single term. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "categories, custom field, tags"
} |
How to enable user_can_rich_edit for guests?
Using wp 3.3beta1 with the wp_editor on the front-end for bbPress.
When calling the editor on the front end, how do I allow a guest to see the visual editor?
I only see options to disable the visual editor site wide, or on a per user basis, but no option to allow guests to use visual? | Just add the `can_richedit` capability to the user you want to be able to use the editor.
You can use the Capability Manager to do it.
**Update:** to enable the rich editor on anonymous/guest users, add this to your `funcitons.php` or anywhere you like, just make sure it comes before the `wp_editor()` call.
add_filter('user_can_richedit', '__return_true'); | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 3,
"tags": "visual editor"
} |
"operation successful" message
i'm writing some custom wordpress pages, and i want that after an action where the user has addess an item to a list (after the user press the submit button and the page reloads showing the updated list) a messagge appears on top of the content area saying something like "the item xxxxxxx has been added." and then fades away after a couple of seconds (or it could stay with an "x" to the right to close it).
There is any function in Wordpress that allows meto do that? The fading is optional, but i want to give the customer some kind of feedback (maybe in a green-border on white box or something like that).
Also optional but interesting would be to have also the error message, all the same just red border instead of green.
The message has to show inside the page, not over and has not to be modal nor an js alert. | WordPress makes use of `add_settings_error()` and related function to setup notifications to display.
Using them is not very straightforward, so easier way might be to make use of hooks like `admin_notices` or `all_admin_notices` to output your own message and style it in same way as WP does. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 0,
"tags": "php, customization, forms, users"
} |
Get post count of current loop when using multiple queries on one page
I'm trying to get a count of the current posts inside of a loop. I'm using multiple loops on one page in my theme. So far I have:
$my_post_count = $wp_query->post_count;
But when I print $my_post_count, it returns the number all of the posts on my WP site. Could it have something to do with using multiple queries on one page? I tried using wp_reset_query after every loop to make sure I wasn't throwing things off that way. What am I doing wrong? | `$wp_query` hold main loop of page and should not be used to create multiple loops.
If you are using new `WP_Query` object then your variable that holds it will have according count:
$my_query = new WP_Query();
// stuff
$count = $my_query->post_count;
If you are using `get_posts()` then `WP_Query` object is not accessible and you should just count returned set:
$posts = get_posts();
$count = count($posts); | stackexchange-wordpress | {
"answer_score": 37,
"question_score": 15,
"tags": "wp query, loop"
} |
Add top-level menu pointing to a different custom post type?
I have a situation where I want to add a second custom top-level menu for a custom post type.
So, when we have a CPT named "fruits", which registers a top level menu with a label of "Fruits", clicking on "Fruits" will take you to `edit.php?post_type=fruits`.
I'm trying to add a separate top-level menu with a label of "Oranges", and when I click that, it actually goes to `'edit.php?post_type=fruits&subtype=orange'`. However, when adding the new menu the link always wants to point to "admin.php"...how can I get it to point to the edit url above?
edit: this seems to work , not sure if it's the best way or not: This actually seems to do the trick, not sure if it's the best way though:
add_menu_page('Oranges', 'Oranges', 'edit_posts', 'edit.php?post_type=fruits&subtype=oranges', ''); | Answering my own question as noted in the edit:
This actually seems to do the trick, not sure if it's the best way though:
add_menu_page('Oranges', 'Oranges', 'edit_posts', 'edit.php?post_type=fruits&subtype=oranges', ''); | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "custom post types, admin menu"
} |
Ugly permalinks stopped redirecting to pretty URLs
I have a WordPress 3.2.1 site hosted on a DreamHost shared Debian/Apache server. Since I set up the site two years ago, it's been set to the `/%year%/%monthnum%/%postname%/` permalink structure. It was also redirecting URLs like `/?p=204` and `/?page_id=1836` to their "pretty" counterparts.
Now, however, I'm seeing entries in my statistics packages (Piwik & Google Analytics) for the "ugly" URLs. Indeed, they're not redirecting to the canonical locations any more.
Does anyone know of a plugin that has been shown to cause a problem like this? Could W3 Total Cache be contributing? I think I updated it sometime in the last few weeks; I was definitely tweaking the settings. (If it helps, my plugin list is published on this page.)
I'll debug manually when I have the time, but meanwhile I thought I'd give the #lazyweb a shot. | Found the following in a plugin file using `grep -Ri 'redirect_canonical' /path/to/wordpress/plugins`:
remove_filter('template_redirect', 'redirect_canonical');
That disables WordPress' built-in canonical URL redirects. Disabling the component of the plugin that contained that line fixed the problem.
Beware the WordPress Mobile Pack's Mobile Switcher.
Hopefully reaching out to the plugin developer will result in a fix that allows both canonical redirects and mobile template switching. Otherwise I'll have to find another mobile plugin. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "permalinks, apache"
} |
Eliminating the appearance of a specific custom field in a post
I would like to suppress the output of one of my custom fields. Is there a way to do this using the `<?php the_meta(); ?>`command? | The function, `the_meta()` allows you to hook to the `the_meta_key` filter (which currently is not documented in the Codex); this is where it fires off:
// wp-includes/post-templates.php @line 744
echo apply_filters('the_meta_key', "<li><span class='post-meta-key'>$key:</span> $value</li>\n", $key, $value);
<
This filter is applied to each and every meta pair, which means that you can add a filter to suppress based on a specific key, value or key/value pair like so:
function wpse31274_exclude_my_meta( $html, $meta_key, $meta_value ) {
if( 'remove_this_key' != $meta_key )
return $html;
return '';
}
add_filter( 'the_meta_key', 'wpse31274_exclude_my_meta', NULL, 3 );
Tried and tested, seems to work, so I hope it helps. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "custom field"
} |
How to link avatar and nickname to profile
On the single post page I want to link the avatar function to the author profile, but I tried
<a href="<?php the_author_posts_link(); ?>">
<img src="<?php echo get_avatar($post->post_author, '64', $avatar); ?>">
</a>
but that doesn't work.
Also, how can I display the nickname (display name) and still link to the profile the following code gives a strange link and 404s
<a href="<?php echo get_author_posts_url(); ?>"><?php the_author_nickname(); ?></a>
some help would be greatly appreciated. Thanks | This a short compilation of the multiple comments above, so that future visitors don't have to read each and every one of them.
First of all, `the_author_posts_link()` is a deprecated function since version 2.1, so `get_author_posts_url()` or `the_author_posts_url()` should be used instead <
The `the/get_author_posts_url()` takes an argument that requires "ID of the author whose URL should be retrieved.", so `the_author_posts_url( get_the_author_meta( 'ID' ) )` will work, and if you decide to use the `get_author_post_url()` instead of `the_author_posts_url()` don't forget to echo it out. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "author, links, avatar, profiles"
} |
My new WordPress blog keeps refreshing in Chrome browser
My new WordPress [blog]: < keeps refreshing in Chrome browser, gets loading error in Firefox, but works normal in IE.
Plugins installed that may cause the problem: Facebook AWD All in One.
Hope someone can help me on this, thank you.
Nathan
* * *
Nov 15, 2011 update
Just to clarify the refreshing problem was not due to PHP cache, for my situation. The function "Activate FB Connect" of WP plugin "Facebook AWD All in One" caused this problem. After I deactivates this function (NOT the whole plugin), this problem gets resolved. Hope this followup can help. | As mentioned, clear your cache. I have no problem with Firefox 7.01 or Iron (Chromium ) on Windows. I would also deactivate all plugins and see if that fixes it. If so then activate them one by one and see if you can find which one causes the problem. What happens if you use another theme? Do you have another computer to test on? The idea is to find out WHY the issue is happening and narrow it down a bit. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "errors, browser compatibility"
} |
Create a blank test.php
Sometimes it's necessary to figure out CSS errors or whatever and then it's great if you have a minimal test page where you just insert the specific code you want to test.
How can I create such an empty test.php? All I could find was this. However, doing so will only create a page that will have the same styling as the page.php one, no?
I suppose I need to put something into my function.php to tell Wordpress that it should create a new template for test.php? How would I do that?
Thanks a lot in advance! :) | I usually do this for just code (no HTML):
add_action('template_redirect', 'test');
function test() {
// code goes here
die;
}
For dealing with HTML I prefer blank theme, set up for testing.
If you want to test in context of existing theme create custom page template, add/remove elements according to your needs and assign to test page. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "templates, testing"
} |
How to detect and display a page only for IE?
I have a theme that does not work in IE so I would like to be able to detect the browser and redirect to a "sorry this doesn't work for your browser" type or what ever solution you guys can suggest for this.
Any ideas on the best way to go about this? | Try using this code to check if it's IE (original source)...
<?php
if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
return true;
else
return false;
?>
You'll have to hook it up with an action and redirect accordingly. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "theme development, browser compatibility"
} |
How to make custom comment fields required and message field not required
I have a comment form that has `name`, `email`, `brief`, `detailed` and `rating` fields.
The `name`, `email`, `brief` and `rating` need to be required, but the latter two are custom fields and I can only make them required through Javascript, but want to add proper WordPress/PHP validation to those fields.
The detailed field is actually the `comment_field` which is currently required, but I want to removed the required for this field, but I don't want to do it via the WordPress settings as I still want `name` and `email` to be required. | Here is a related question that should answer yours. Basicly you want to use the `pre_comment_on_post` hook
function custom_validate_comment() {
//validate for brief and rating
if( empty( $_POST['brief']) || empty( $_POST['rating']) )
wp_die( __('Error: you must fill in both the rating and the brief') );
//make comment not required
if(empy($_POST['comment']){$_POST['comment'] == "empty_comment";}
}
add_action('pre_comment_on_post', 'custom_validate_comment');
function custom_change_comment( $commentdata ) {
if( $commentdata['comment'] == 'empty_comment' )
$commentdata['comment'] = '';
return $commentdata;
}
add_filter('preprocess_comment', 'custom_change_comment');
That should at least get you on the right track | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "custom field, customization, comments, validation"
} |
Remove the current item from a menu
I have a menu. It has two items:
* the first is a link ("Index", www.domain.com)
* the second one is a link to a category page
I have the requirement to remove the first link when I'm on the index page and remove the second link when I'm on that category.
Ideas? | The code that this menu produces is this:
<ul id="dd" class="dd">
<li id="menu-item-142" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-142">
<a href="
</li>
<li id="menu-item-102" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-102">
<a href="
</li>
</ul>
I fix it adding this to the css file:
#dd .current-menu-item {
display:none !important;
}
Wordpress is kind enough to add anchor css styles that can be used. i have the `#dd` prefix so that this only works on this menu and not all the others.
Hope this helps. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "categories, menus"
} |
How to Create RSS Feeds for categories in Wordpress?
I want to create RSS feed for categories in WordPress.Is this possible? How could I do it?
Thanks | Category feeds are a part of WordPress core. e.g. for category `foobar`, the RSS feed link is:
www.example.com/category/foobar/feed
Easy-peasy! | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 2,
"tags": "rss, feed"
} |
Random HTTP 500 error in WordPress
I'm running WordPress 3.2.1 on a CentOS box and I'm getting reports from my writers saying they get HTTP 500 errors when they try to update an exciting post.
I've tried the same and have similar problems (although the HTTP 500 only shows in Chrome, Safari and Firefox simply give me a blank window).
I've increased my log level on my httpd install to debug but I still can't find any errors in the logs....
The same box is running another website as well, also using WordPress (same version) and this site is not displaying these symptoms.
All suggestions on how to resolve this are more than welcome!
EDIT: I should also add that I've already tried increasing the PHP Memory in wp-config.php (up the 64MB) but the problem still occurs)
(I'm double-posting this between here and serverfault as I'm not sure wether the problem is related to the server itself or to wordpress...) | If the problem is easily reproducible (i.e. you can make it happen again and again by following a set of steps), do this:
* Step 1: Document the steps required to cause the problem.
* Step 2: Document all of the plugins you have running
* Step 3: _Deactivate all of your plugins!_
* Step 4: Perform the steps outlined in step 1
* Step 5: If it's still broken, then you've got a config error somewhere on your server.
* Step 6: Activate the first plugin in the list from step 2.
* Step 7: Perform the steps outlined in step 1
* Step 8: Repeat steps 6-7 with every plugin until the site breaks to figure out what the culprit is.
I had this recently happen on my system, and it turned out to be a name conflict between two plugins I had running on my site.
Also, enable `WP_DEBUG` in your `wp-config.php` file ... you might see a better error message, but no promises. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "errors, http, troubleshooting"
} |
How to output all taxonomy links from a custom post type in a menu?
I made a custom post type called Product. And a taxonomy with the name 'product-category'. These taxonomies have pages where we show a list of the products that have that taxonomy.
Now my question is how to get all the taxonomies as a menu in the header. Its an awful lot of work to add it manually in the menu editor. Also because i need sub-menu's and sub sub menu's. How do I do this? | You can use wp_list_categories() which by default, generates nested unordered lists (ul) and just pass `product-category` as the taxonomy parameter for example:
add_filter('wp_nav_menu_items','add_custom categories', 10, 2);
function add_custom categories($items, $args) {
$items .= '<li>' . wp_list_categories( array('echo' => 0, 'taxonomy' => 'product-category', 'title_li' => 'Product Categories') ) . '</li>';
return $items;
} | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "posts, taxonomy, menus, customization"
} |
How to count get_users query?
I have been searching high and low for a way to count the amount of results from a get_users query.
Most of what I found is to count the total number of posts in a post query, but nothing for counting the total number of users in the get_users query.
Can someone point it out for me? Thanks a lot. | when you use **`get_users()`** it retrieves an array of users matching the criteria given in `$args` which means you can simply use PHP's `count()` function e.g:
$users = get_users($args);
$number_of_users = count($users); | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 3,
"tags": "query, users, count"
} |
Edit image / Delete image link
There is a function in Wordpress that allows to display a "edit post" link if the user has sufficient rights.
<?php edit_post_link( __( 'Edit' ), '<small class="edit-link">', '</small>' ); ?>
Is there an equivalent for media files / attachments,
UPDATE This sorts of work
$images = fdw_get_post_images('preview-onepost-thumbnail');
if ($images){
$counter= 0;
foreach ($images as $image){
$src = $image['src'];
$info = $image['info'];
edit_post_link( __( 'Edit image' ), '<section><small class="edit-link">', '</small></section>', $info->ID ); ?>
But the user actually need to be able to Delete the image. That screen does not allow it. | This isn't 100% complete, but should be a good start for you.
<a href="<?php echo wp_nonce_url( "/wp-admin/post.php?action=delete&post=$post->ID", 'delete-attachment_' . $post->ID ) ?>"><?php _e( 'Delete Permanently' ) ?></a>
A couple notes on what you'll have left to do:
* This will do no confirmation, so you'll probably want to use JS to verify that it wasn't clicked by mistake
* This will redirect back to the current page, which will no longer exist. The URI may look something like, `?attachment_id=704&deleted=1`. You'll want to intercept front-end attachment requests where `$_GET['deleted'] == '1'` and handle that gracefully (e.g. redirect). | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 5,
"tags": "attachments, media library"
} |
Obfuscating Email Addresses in Form Fields
I'm writing a WP Theme where registered users can email post authors sending them en email from the post's page itself.
So I created a contact form in which I get the user and author infos and emails and I put them in hidden input fields to pass them to the php mail function.
Does WordPress have a way to obfuscate the post author's email address, to protect it from scrapers? Is there a better way to implement this functionality, other than outputting the author email address in the form field?
Thanks! | Core function to obfuscate mail addresses:
antispambot( $emailaddy, $mailto );
Second arg is 0 or 1 and optional. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 2,
"tags": "email, forms, contact"
} |
Image menu showing categories in page
I'm trying to display different images in a page that links to categories.
Currently i have a page that shows the categories and the pages for the categories but it needs a slight change.
I need to display the category name with an image for that category and a background for it. I've attached an image to explain what i mean properly.
I think the part i'm having trouble with is the background image and the image for the category. I can get it to display the category name it's just the background image and the image for the category.
What's the best way to do this in wordpress?
Here's a link to the design. <
In this design Products is the page title and the four sections are different categories. Clicking on Printers for example will take you to another page show the same thing but with sub categories of printers. | I would suggest looking at a plugin like images for categories and seeing if you can extend it to allow 2 images per category. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "categories, images"
} |
Can't add a Page with Name 2011
I've no idea why i can't add a Page with Name `2011`. Wordpress changes the URL Slug to 2011-01.
There is no Post with this Name in my Database. I tried zu flush my rewrite rules but nothing seems to be work.
If i add a Page 2013 it works fine. But only once... If i delete this Page (from Trash) i can't add it again. Wordpress changes the slug to 2013-01. If i change the Post name directly in the database. Nothing happens...
I really wonder why because there is no Post with this Name.
Any suggestions? | This has to do with how paging-within-a-page works. See ticket #5305. There's a plugin that will allow you to have numeric slugs if you're willing to sacrifice paging: < | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 3,
"tags": "permalinks"
} |
How to change author base without front
I am currently using this code:
function change_author_permalinks() {
global $wp_rewrite;
$wp_rewrite->author_base = 'connect/member';
}
add_action('init','change_author_permalinks');
but my current `front` set on my blog is:
`share`
So the above generates a URL like so:
`
But I don't want `/share/` as part of this author URL. I cannot remove the `/share/` front as it is needed for other parts of the site.
How do I set the author URL to not use `front`? | This is the best solution I have come up with but I welcome better ways:
function change_author_permalinks() {
global $wp_rewrite;
$wp_rewrite->author_base = 'connect/member';
$wp_rewrite->author_structure = "/" . $wp_rewrite->author_base . '/%author%';
add_rewrite_rule('connect/member/([^/]+)/?$', 'index.php?author_name=$matches[1]', 'top');
}
add_action('init','change_author_permalinks'); | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 4,
"tags": "permalinks, url rewriting"
} |
Outputting post title without encoding
I'm setting up a way to feed the title of a WP post as the title argument for a reddit button. It works fine unless there is an encoded character in the string:
apostrophe’s break things.
...Which results in reddit double encoding the ampersand:
apostrophe&#8217;s break things.
I've tried the functions the_title_attribute(), the_title(), html_entity_decode(), and htmlspecialchars_decode() all to no avail - certain encodings remain.
Anyone know a way around this? Like a way to get the raw unencoded title from the database?
Thanks! | Try this:
$title = get_post_field('post_title', $post_id, 'raw');
However I'd get to the bottom of what encoding reddit code would prefer. Echoing raw stuff is poor idea for security. | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 1,
"tags": "encoding"
} |
Problem with WordPress output text ('esc_html' & 'wp_richedit_pre')
I have a problem with output text. When I editing text in the WordPress control panel everything looks normal:
but when I output it to the html:
<?php esc_html( wp_richedit_pre( $_product->details ) ); ?>
It looks like this:
What could be wrong? Please for help. | hmm ... strange. I looked to the file ' _wp-includes/formatting.php_ ' on the functions _wp_richedit_pre_ :
function wp_richedit_pre($text) {
// Filtering a blank results in an annoying <br />\n
if ( empty($text) ) return apply_filters('richedit_pre', '');
$output = convert_chars($text);
$output = wpautop($output);
$output = htmlspecialchars($output, ENT_NOQUOTES);
return apply_filters('richedit_pre', $output);
}
Instead ' _wp_richedit_pre()_ ' I used ' _wpautop()_ ' and it works.
Thanks for the hint _Soulseekah_. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "functions"
} |
Easy way to update a single translation entry without having to translate
I'm using the "Featured Image" meta box which allows you to attach a secondary thumbail to a post. The title for this box is defined in the Wordpress codebase like so:
__('Featured Image')
Which looks to be a wrapper for the translate methods. I'm wondering how to change this text without having to do any translation files. Is it as simple as an action or filter hook? | Sure, the `gettext` filter does exactly what you require.
Here's some code that should work out of the box:
function wpse31449_translate_my_stuff($translation, $text, $domain) {
if ($text == 'Featured Image')
return 'Post Image';
return $translation;
}
add_filter( 'gettext', 'wpse31449_translate_my_stuff', null, 3 );
Note: if the translation is retrieved with a gettext context (`_x()` and `_ex()`) then the `gettext_with_context` filter has to be hooked to, which passes 4 arguments - the translation, the original string, the context and the domain to your filter.
Let me know if the answer is clear and/or how I can further improve it. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "post thumbnails, translation"
} |
Minification Plugins break my website
Well, my blog is a bit Image Heavy to say the least. I've been using different types of minification plugins, but they all seem to break my site.
When I tell the plugins to compress and join my css & javascript files... it completely gets rid of them and my site becomes nothing but an unorganized mess of text and pictures. Is there something I can do with my blog so that minification will work?
The only one that doesn't seem to break my website is one called 'Better Wordpress Minify'... but that plugin has almost NO effect on my websites performance. | This is normal, minification of CSS/HTML and JS is not a magic button. If you have no plugins and 1 style-sheet and minimal javascript (aka not more than 1 function) it will work, but anything above that and your looking at conflict and load order problems.
To properly minify takes work, you have to either do it manually or figure out what is causing the conflict and fix it, in many cases it's simply not worth the trouble. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "plugins, performance"
} |
How to create a clone role in wordpress
How to create new role with same capabilities of existing role. Eg: I would like to create a new role with same capabilities of administrator or editor and so on.. | Try this... This should work.
<?php
add_action('init', 'cloneRole');
function cloneRole()
{
global $wp_roles;
if ( ! isset( $wp_roles ) )
$wp_roles = new WP_Roles();
$adm = $wp_roles->get_role('administrator');
//Adding a 'new_role' with all admin caps
$wp_roles->add_role('new_role', 'My Custom Role', $adm->capabilities);
}
?>
Check it. | stackexchange-wordpress | {
"answer_score": 43,
"question_score": 28,
"tags": "user roles, capabilities"
} |
Custom Post Type / Tab Limit
I've created a site with **nine** (gulp) custom post types. It's a huge site unsurprisingly.
The 9 post types fit on the admin menu but I was wondering if there is a limit to the number of extra post types you are allowed in WordPress?
Say this because when enabling PollDaddy that adds two more tabs (Polls and Ratings) which then hides two of my custom post types from the menu.
Anyone know if there's a limit and how/if I can increase it?
I may try adding a 10th custom post type and see if that displays | The problem is probably due to clashes in the `menu_position` argument when registering a post type. Try editing those to values between the standard multiples of 10 and see if it solves the problem. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "custom post types, admin menu"
} |
WP-PostRatings - how to make rating show up?
I have Boldy theme on a 3.2.1 instance of Wordpress.
I have installed the plugin WP-PostRatings.
I want it to show up on my individual posts when posts are viewed individually on a page.
* I installed and activated the plugin.
* I added
`if(function_exists('the_ratings')) { the_ratings(); } ?>`
within my _single.php_ file, as shown in pastebin.
However, nothing is happening with my blog posts when viewed as single pages.
Have I put the code in the wrong place/file? | few things you can check
1. the code is within the loop
2. the plugin is activated
3. check plugin option page and select a rating type
4. check page source code and see what is being generated.
5. if all ok. your css is not blocking any rating star tag.
6. de-activate, uninstall, delete and re-install the plugin | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "plugins, plugin wp postratings"
} |
Location of twentyeleven theme's option filters?
Hi I'm learning theming options based on the existing theme TwentyEleven.
I've come across the following code in inc/theme-options.php
return apply_filters( 'twentyeleven_default_theme_options', $default_theme_options );
I can't seem to find the add_filter for 'twentyeleven_default_theme_options', or does it not even exist? | I don't believe there _is_ an `add_filter()` call anywhere. If you want to override the option defaults, you can call your own `add_filter()` to do so, either in a Plugin or in a Child Theme.
**EDIT**
An `apply_filters()` call is nothing more than a _filter hook definition_ : basically, it is defining the data to which a filter hook is applied.
It is similar to `do_action()`, which is an _action hook definition_ : it defines the template location/runtime execution point at which the action hook is fired.
So, the presence of `apply_filters()` **does not imply** that there will necessarily be a corresponding `add_filter()` call; rather, it merely means that a filter is **available** to modify the specified data.
On the _other hand_ , the presence of `add_filter()` **does imply** that somewhere, a corresponding `apply_filters()` call exists - just as the presence of an `add_action()` call implies that somewhere, a corresponding `do_action()` call exists. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "theme twenty eleven"
} |
What function changes a post's timestamp?
What function changes a post's timestamp? I created a post from frontend script, but I need to add a date picker to set the date of the visit. | You should be able to submit the following information to set a custom date
$_POST['aa'] // Month
$_POST['mm'] // Day
$_POST['jj'] // Year
$_POST['hh'] // Hour
$_POST['mn'] // Minute
$_POST['ss'] // Second | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "timestamp"
} |
Plugin to hide image in excerpt
I was looking for a plugin that will enable me to hide an image on the excerpt, but show it on the single post view. Anyone knows if there is any? | According to the wordpress documentation this is how it is supposed to work out of the box. Maybe I misunderstood the question, but by default the excerpt should strip html tags and graphics. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 0,
"tags": "plugins, plugin recommendation, post thumbnails, images"
} |
Display content from "About Us" page on the Home Page
I have a page called "About Us" with some static content. I want to display that static content on the home page. Would I need to do a custom query that returns the about page, or is there a better way?
$about_page = new WP_Query('p=7'); // is this basically it?
Is there a better way to do this? A more dynamic way that would allow me to distribute this theme to others who don't have a specific ID for an About page.
EDIT:
Found this page on the Codex. It recommends using the get_page function. | If you're using WP_Query, then assign that page a custom meta key 'home_content' with a value as 1. Then use WP_Query's custom field parameters to loop over it. If you can restrict the title as 'About' everywhere, use get_page_by_title, and if you can restrict the slug as 'about', use get_page_by_path. These methods will work dynamically. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "loop"
} |
How to determine if an admin is logged in outside the loop
I need to be able to tell if an admin is logged in ouside of the loop.
This is needed for some php files that are part of a WP site but do not use `require( '../wp-load.php );`
What I need to do is keep the Google Analytics tracker JS from firing for logged in admins, but track everyone else.
How do I find out if an admin is logged in outside of the loop? Checking the WP logged in cookie? Or must I use `wp-load.php`? | You can use current_user_can() to determine if an admin user is logged and load your Google tracking code using wp_enqueue_script with an if statement in functions.php
if ( ! current_user_can( 'edit_posts' ) ) {
wp_enqueue_script( 'google-tracking');
} | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "admin, loop, login, outside wordpress"
} |
Form Value of drop down category + Translation of 'show option none'
I am building a form where a user can submit an article from the front end..
So far so good... To this form i am doing some submission check using javascript..
When i get to check if a category is choosen
This is the line the retrives categories in the form:
<?php wp_dropdown_categories('show_option_none=---------------->&taxonomy=category&hide_empty=0&name=cats[]&orderby=name&hierarchical=1'); ?>
I dont know how to check it.. what is the value being sent to wordpress? Also.. Can i change this:
show_option_none=---------------->
into somthing i can translate using the regular tranlation method aka __() or _e()??
Thanks guys | Ok... as thing go when your trying to solve somethimg you have no peace until its fixed so.. i went ahead and did some clear mind thinking (after a night sleep) and got that i can check the HTML for the values returen.
**Just wanted to share incase anyone stumbles with the need for this info**
This:`<?php wp_dropdown_categories('show_option_none=---------------->&taxonomy=category&hide_empty=0&name=cats[]&orderby=name&hierarchical=1'); ?> `
Returns a value of the category number for each select item which is easy to check.
Also.. about the translation part this is the right way to do that..
<?php
$choosecatmsg = __('Choose A Category', 'blue_article_demon');
wp_dropdown_categories('show_option_none='.$choosecatmsg.'&taxonomy=category&hide_empty=0&name=cats[]&orderby=name&hierarchical=1');
?>
Thanks for anyone who took a look while i was stuck :) | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "categories, dropdown, select"
} |
How to shorten the Permalink after WP>WP blog import?
We've imported a blog from one domain to another and the permalink thats been created for category archives is: domain.com/category/graphic-design-blog/tips-for-artist/ where **category/graphic-design-blog/** is superflous.
The permalink structure is set to the default (2011/10/post-name) and this is working fine for single posts.
Yoast's WP SEO plugin is installed, but there are no changes made under the permalink section of the plugin.
Any suggestions as to why this is happening / how I can fix it?
Thanks, Tim | Sorry [no-one ;)], I figured it out:
* /category/ can be removed in Yoast SEO by checking ' **Strip the category base from the category URL.** '
* The other part 'graphic-design-blog' was displayed because all of the categories were had the parent 'blog' which had the slug 'graphic-design-blog'. **I set all the sub-categories to have the parent: none.**
Embarrassingly simple :) | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "permalinks, url rewriting, import"
} |
Retrieving a Value from a wp-database
why my sql statement is not returning any value.. is this wrong?
<?php
global $wpdb;
$result = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->wp_frm_item_metas"));
foreach ($result as $item){
$eventname= $result->meta_value;
}
?>
<h2><?php echo $eventname;?></h2>
What I'm doing is, I'm displaying the data stored in database using formidable form.. (not pro).. Is there something wrong with my code? | I believe for your foreach function should be like below:
foreach ($result as $item){
$eventname= $item->meta_value;
} | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "plugins, database, forms, sql"
} |
How can I add authors in WordPress and assign them a picture?
I know that Wordpress allows us to create a new user and the user's avatar is got from Gravatar service base on their email. How can I add authors in WordPress and assign them a picture (without using Gravatar service ) ?
Thank you !
P/S: I am sorry for my bad English. :) | there are a bunch of plugins that adds this functionality to wordpress, this one seems pretty neat, User Avatar | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "users"
} |
How to exclude a particular category from the category list
I'm trying to edit a wordpress theme.
The following is the section of code where the list of categories is retrieved and displayed in a drop-down menu.
<p>
<label for="entrycat">* <?php _e( "Question category:", "sofa_qanda" ); ?></label>
<?php
$select = wp_dropdown_categories( 'show_option_none=Select&show_count=0&orderby=name&echo=0&hide_empty=0' );
$select = preg_replace( '|<select(.*?).*?>|i', '<select id="entrycat" name="entrycat" tabindex="4">', $select );
echo $select;
?>
</p>
I what to exclude a particular category, say category id 10 from the list. How do I do that? | <
use the 'exclude' parameter; example:
$select = wp_dropdown_categories( 'show_option_none=Select&show_count=0&orderby=name&echo=0&hide_empty=0&exclude=10' ); | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "categories"
} |
How can I add a box to edit Order on a regular post?
I'm currently using the menu_order field in the DB to have some custom ordering of posts. I want to expose this field to the user via the admin section, like it is when editing a Page (in Page Attributes).
Is there a simple way to do this? | <?php
add_action( 'init', 'wpse31629_init' );
function wpse31629_init()
{
add_post_type_support( 'post', 'page-attributes' );
}
Add that to your `functions.php` or in a plugin file and you'll get an attributes dialog box with the menu order input. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "posts, admin, post editor, order"
} |
Admin - Load existing admin template as a submenu page
I'm trying to save my client a few clicks. I've created a custom role of "Customer" and I'd like to get them to that screen, without having to have them click "Users" and then select the "Customer" role.
So, I have a custom menu called "Orders". I'd like to add a submenu called "Customers" and "load" this page:
users.php?role=custom
I'm guessing I have to use the callback function on add_submenu_page and then load that template? What's the right way to go about this? | You can add an interal link quite easily, it's the same approach you use for adding custom items, you simply exclude a callback function and set the menu slug to the applicable URL, here's an example.
add_action( 'admin_menu', 'add_user_type_link' );
function add_user_type_link() {
add_submenu_page( 'users.php', 'Customers', 'Customers', 'edit_users', 'users.php?role=customers' );
}
Adjust the code as appropriate(required cap, naming, etc..). | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "admin, sub menu"
} |
how to remove indent from twently eleven comments reply
how i can remove indent from comments reply if someone reply comments it indent to previous reply and keep adding indent..how i can make it just indent first reply and other show under this..
i searched for solution on google and stackexchange but could't find any..its output simple ordered list for comments and reply to comments with different classes added to list
HTML OF COMMENTS
<ol>
<li></li>
<li></li>
<li></li>
<li></li>
</ol> | If you want to get rid of threading completely you can control it in `Settings` > `Discussion` > `Other comment settings` > `Enable threaded (nested) comments`.
If you want to keep functionality and markup, but change it visually you would need to do that via CSS, which (as per comment on your question) is not really WordPress-specific. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": -1,
"tags": "comments"
} |
Hook for page Request?
I want to run a function that looks at the current url params of the page that is requested and sets a cookie based on those params.
So, I guess I'm looking for:
1. The Wordpress Hook that allows me to do this before the page is even loaded
2. A way to get the requested URL | // Kick in right before theme takes over, when WP is all loaded
add_action('wp', function(){
list($uri, $qs) = explode('?', $_SERVER['REQUEST_URI']);
// Do stuff here:
// ... STUFF ...
});
Cheers! | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "plugins, plugin development, hooks, actions"
} |
Single Page Design, Storing in Theme Options
So I'm developing a theme where essentially all content will be displayed on a single page (index).
Well, the content isn't exactly conventional. In other words, it's not just a title and body, maybe a few custom post fields. It's very different from section to section.
What I was thinking of doing was just creating all of the content fields using the Theme Options API. So, instead of editing a page, you just go into the theme options area and fill in the content for each section.
My main question is... is there a limit to how much data should be stored as "theme" options? Or, after understanding what I'm doing, is there a better way of accomplishing this? | Option values are `longtext`. So you can store up to 4,294,967,295 or 4GB (232 – 1) bytes in an option value. I wouldn’t do that … but feel free to test the edge cases. :) | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "theme development, themes, theme options, single"
} |
why is this script not working on my site
I found a script so I can take care that on some months I can change the number of post at a page.
So I implment this script at this way : <
But still all articles are displayed as you can see here : <
Anyone a idea why and how to solve this ?
Roelof
Edit 1 :
What I want to achieve is this in pseudo code.
When the year is 2005 and the month april(04) and we are on the first page of that month then 1 article must be displayed. if not then the standard number of articles must be displayed. | Consider this option of achieving what you seem to be requiring:
function wpse31701_filter_query() {
global $wp_query;
// Check year and month
if ( $wp_query->get( 'year' ) == 2005 and $wp_query->get( 'monthnum' ) == 5 )
// Check page number to apply offset
if ( $wp_query->get( 'paged') > 1 ) $wp_query->set( 'offset', 1 );
else $wp_query->set( 'posts_per_page', 1);
}
add_action( 'pre_get_posts', 'wpse31701_filter_query' );
Here we alter the query as soon as `$the_query` is ready to get the posts, to modify the `posts_per_page` to 1 if `paged` is 1, and apply and offset of 1 post if `paged` is > 1.
The important thing is to apply `offset` and `posts_per_page`; the rest is purely conditional so apply to taste. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "themes"
} |
Get users with atleast one post
How can I get all users with atleast one post? I don't think it's possible with `get_users` function. | global $wpdb;
$min_posts = 5; // Make sure it's int, it's not escaped in the query
$author_ids = $wpdb->get_col("SELECT `post_author` FROM
(SELECT `post_author`, COUNT(*) AS `count` FROM {$wpdb->posts}
WHERE `post_status`='publish' GROUP BY `post_author`) AS `stats`
WHERE `count` >= {$min_posts} ORDER BY `count` DESC;");
// Do what you want to $author_ids from here on...
This will return the **User IDs** of the Authors with _5+ published posts_ and orders them descending, by post counts. | stackexchange-wordpress | {
"answer_score": 7,
"question_score": 4,
"tags": "users"
} |
Where to put third party PHP library?
I'm developing a couple of open-source plugins and a theme (all part of a "suite") that all use the same third party PHP library. I'm wondering what is the best way to include it in Wordpress. Here are some thoughts:
* put it in one of the plugins and require that plugin to be installed and activated
* create a special "core" plugin that does nothing but including it
* put it directly in `wp-content`
Any thoughts on that matter? | If each plugin/theme functions on its own, then you should probably drop the the library in every theme/plugin.
Then just check to see if it a class or function from the third-party library exists before requiring it.
<?php
if( class_exists( 'SomeClass' ) )
{
// require/include here
}
or
<?php
if( function_exists( 'some_function' ) )
{
// Require/include stuff here
}
Alternatively, you could wrap every function/class/variable/constant from the third party library in a check to see if it exists, like pluggable functions.
If all of the plugins and the theme are dependent on one another, then it doesn't really make much sense to divide them up and you should probably rethink that. | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 9,
"tags": "plugin development, customization, library, third party applications"
} |
how to edit wp category widget
how to edit wp category widget, so it would not show one of specified category? For example, it shows all categories in list, and I need to remove category Books, from it, how can I do it? Best regards, Y2ok | // This alters the get get_terms() arguments and hides some categories
function widget_category_excluder( $args ) {
// Replace the numbers with category IDs you need hidden
$args['exclude'] = $args['exclude'].',1,2,3,'; // Keep it safe!
// Or use exclude_tree to exclude children categories also
// $args['exclude'] = $args['exclude'].',1,2,3,'; // Keep it safe!
// (,1,2,3, is enclosed in ',' to ensure digits don't get welded)
// Test and see what fits your needs best
return $args;
}
// This allows hooking into WP_Widget_Categories and excluding Terms
add_filter( 'widget_categories_dropdown_args', 'widget_category_excluder' );
add_filter( 'widget_categories_args', 'widget_category_excluder' );
Add this code to your **functions.php** and experiment. It's a quick fix. A better alternative is a custom widget with the possibility to hide categories.
Regards. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "categories, php"
} |
Dynamically append custom post type to end of url
At the moment my nav menu's category list only links to normal post_type archives. I'd like to dynamically append a custom post type, specifically ?post_type=portfolio, to the end of each url that particular drop down list. But I really don't know anything about php regex at the moment, except that I think that's what I need for it to work.
This is the code I've got in my functions.php file so far, specifically for the drop down list in question. As you can see, my theme appends the categories post count after the end of the link, and I'd like to keep it there please.
$folio = wp_list_categories('show_count=1&echo=0&child_of=86&title_li=<a href=" title="View all Portfolio items">Portfolio</a>');
$folio = preg_replace('/\<\/a\> \((.*)\)/',' <span>$1</span></a>',$folio);
echo $folio;
Thanks | Here is something I came up with to solve this exact problem.
add_action('wp_list_categories','example_wp_list_categories');
function example_wp_list_categories($output) {
global $post;
foreach (get_categories() as $cat) {
if (preg_match("/\/category\/$cat->slug\//", $output)) {
$output = str_replace('/category/' . $cat->slug . '/', '/category/' . $cat->slug . '/?post_type=' . $post->post_type, $output);
}
}
return $output;
}
Regex isn't a strong point of mine, so that might be improved upon. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "php, url rewriting, regex"
} |
Adding a filter to my posts
Hello guys I would like to append a link to the end of the content within my post. I currently have this in my functions.php file:
function ifcj_comment_link() {
global $post;
return ' <a href="'. get_post_meta($post->ID, 'Israel In The News Audio Link', true) . '">' . __( '<div id="audio-player">Testing</div>', 'ifcj' ) . '</a> ';
}
function ifcj_custom_excerpt_more( $output ) {
if ( has_excerpt() || in_category( _x('israel-in-the-news', 'israel-in-the-news category slug', 'ifcj') ) &&! is_attachment() ) {
$output .= ifcj_comment_link();
}
return $output;
}
add_filter( 'get_the_excerpt', 'ifcj_custom_excerpt_more' );
It displays just fine in my categories feed page: <
But that particular link is not showing up on the archive.php page.
Am I missing something here?
Thanks | **The excerpt must be used by the Theme.** I don't think it is. Use **'the_content' filter** to append to the post. Excerpts are usually used in feeds and only by certain themes.
add_filter('the_content', function($content){
if(!is_archive()) return $content;
global $post; // This is the current output post
ob_start();
// Echo stuff to append to post here! (your link or whatever)
return $content.ob_get_clean();
});
_PHP 5.3 Closure used. Extract function yourself aside for PHP 5.2._
Regards. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "functions, excerpt"
} |
get_children filter with postmeta
I am doing the following to get all the children associated with a post:
$args = array(
'order'=> 'ASC',
'post_parent' => get_the_ID(),
'post_status' => 'publish',
'post_type' => 'task'
);
$tasks = get_children( $args );
Now the posts of type `task` have postmeta associated with them. One particular meta_key is `task_progress`. I would like to get all the children whose `task_progress` meta_value is less than 100. What is the best way to filter the results? | This should do the trick:
global $wpdb;
$parent = 1; // Make sure it's int (intval() it) as it's not escaped in the query
$posts = $wpdb->get_results(
"SELECT `post_id` AS `ID`, `meta_value` AS `Progress` FROM {$wpdb->postmeta}
WHERE `meta_key`='task_progress' AND `meta_value` < 100 AND `ID` IN
(SELECT `post_id` FROM {$wpdb->posts} WHERE `post_parent`={$parent})
ORDER BY `meta_value` DESC, `post_id` DESC;" // Sort descending
);
foreach($posts as $post){
$progress = $post->Progress;
$post = get_post($ID = $post->ID);
// Print here
}
_Regards_. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "post meta"
} |
How do I programmatically set default role for new users?
I would like new users of the blog to have custom role, rather then Subscriber. How do I set this programmatically? I know that it can be changed from the backend. | This allows plugins to easily hijack the default role while they're active.
// Hijack the option, the role will follow!
add_filter('pre_option_default_role', function($default_role){
// You can also add conditional tags here and return whatever
return 'subscriber'; // This is changed
return $default_role; // This allows default
});
I use it to make sure some plugins that need subscriber roles get it regardless of Administrator attempts to change :)
_Regards_. | stackexchange-wordpress | {
"answer_score": 15,
"question_score": 13,
"tags": "user roles, users, user registration"
} |
Looking for a theme to show unread/updated posts since last visit or like that
Good morning WP fans !
I try to find a theme for a .wordpress.com blog (it's hosted there) What I would like to have is a "notification system", like for example to notify the visitor that there are updated/unread posts in a category since his last visit/refresh/whatever. Like for example with a **bold number** inside brankets next to a category. Or with ANY other way if that is possible.
Do you know of any theme that has that functionality ?
Thanks !!! | What you're looking for is a combination of
* KB New Posts, which shows visitors posts that they have not yet read
* Smart Unread Comments
* and some notification bar system, one of these four may make a good choice
Of course you will have to couple them yourself to suit your needs and requirements. As far as I know there is no such plugin for WordPress.
Additional ones that you may want to dig in are:
* WP Since Last Visit Plugin
* Published Articles Since Last Visit
Again, none of them will work just like you're imagining it, probably, so you'll have to write your own using the concepts those plugins use. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "themes, notifications"
} |
How can I UN-attach media from a post?
I'm having a trouble un-attaching media from a post without deleting it entirely from my site. Is there a simple way to unattach an image from a post for instance? | I learned from Brian Fegter that you can Un-attach an image from a post while participating in this question: Can I attach an image to a different post?
It isn't exactly "simple", but not to difficult. It's the only solution I've been able to find. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 5,
"tags": "attachments"
} |
Master menu item for multiple plugins?
I guess this question is more or less about aesthetics and organization rather than functionality, but I'm curious nonetheless...
I know I can add a custom menu item in the dashboard for my plugin using the `add_menu_page()` function, but my question is: Is it possible to add a "master" menu item with "sub-menu" items which would correlate to individual plugin options pages?
In other words, let's say my company name is "Guru Guy" and I have released 4 different plugins... Would it be possible to create a menu item that looked something like this:
> Guru Guy <\-- Main menu item
>
> \-- Plugin 1 <\-- Plugin 1's options page link
>
> \-- Plugin 2 <\-- Plugin 2's options page link
>
> \-- Plugin 3 <\-- Plugin 3's options page link
>
> \-- Plugin 4 <\-- Plugin 4's options page link | Yes,
<
Specific to your question `add_submenu_page`: < | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "plugins, plugin development, admin menu, add menu page"
} |
Subsite with different template, and content
I have a Wordpress blog hosted on a shared web server: <
I would like to add a whole new "area" to this site, called Consulting. When navigating to < \- another template with different navigation should be used, and the frontpage should be blog posts for that specific area.
This also means, that the blog posts I write for the Consulting area should not be displayed on the front page of the root domain.
I use the Genesis framework, but I think that might be my problem. It doesn't seem to support this setup.
Any suggestions for frameworks, themes, or plugins?
**Code**
function exclude_category( $query ) {
if ( !$query->is_category('hardware')) {
$query->set( 'cat', '-1' );
}
}
add_action( 'pre_get_posts', 'exclude_category' ); | The framework is not the problem. You just need to exclude your Consulting category from the loop each time you have it. Then use a custom template for the marketing page. Another option would be to set up a multi-site install and then use Consulting as its own blog.
**EDIT:**
To exclude the category try adding this to your themes function.php
function exclude_category( $query ) {
if ( !$query->is_category('consulting')) {
$query->set( 'cat', '-1' );
}
}
add_action( 'pre_get_posts', 'exclude_category' );
Edit 2: fixing the problem chip mentioned below. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "multisite"
} |
All posts display default index.html
I am setting up a wordpress blog on a Ubuntu LAMP with ispconfig 3 and freedns.afraid.org. I have everything set up, can log in to domain/wp-admin to create posts, etc. But the blog views as the "Welcome to your website!" ispconfig page. What should I check to figure out what is wrong?
Thanks! | Delete or rename index.html as it's the default file served if it's available. This should then allow the server to start displaying your site files. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "posts, admin"
} |
How to Automatically jump to the corresponding language of the page using WPML plugin in wordpress
I'm setting up a multi-language blog using WPML. I works well using the button to change the language. Is there any way to automatically jump according to the Browser's language? My WPML version is 2.0.4. | yes under, WPML-->Languages--->Browser language redirect.
Select one of the 3 options and hit "apply". | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "plugin wpml"
} |
Print WordPress template filename(s) for debugging
I've taken over the maintainance of a large WP-MS powered site. The site has ~200 templates, many page specific, and with no standard naming procedure.
It would save a lot of time if while surfing around the site I can see the template names which make up the current page. Is this possible? I've looked at the debug plugins for WordPress, but they appear geared towards variables and SQL queries, not templates. | this is also a quick way;
<!--
<?php print_r( debug_backtrace() ) ?>
-->
paste it just before the closing tag | stackexchange-wordpress | {
"answer_score": 6,
"question_score": 8,
"tags": "templates, debug"
} |
Add some fileds to the wp_posts table
I need to extend some wp tables (wp_posts, wp_comments, wp_users) to store some additional fields. I can't use metadata because I need to query those values directly via MySQL. I need an help to choose if it's better to extend the original table or to define an additional one with those fields, with a 1-1 relationship to the original one. This second case will require an additional JOIN. Thanks.
eV | The second approach (joining additional table) is better for several reasons.
* When plugin is not active, you won't retrieve it's data (or with other words, you won't select additional data unless you explicitly join it)
* It's more maintainable. You can alter your plugin table without altering posts table and vice versa.
* The join most likely won't hurt performance, but may improve it if there are a lot of updates \- (one more post on the same topic) | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "plugins, database, customization"
} |
WordPress Subpages Fancybox Trouble
I have a website that I'm converting over from a static html site to WordPress. I got almost everthing done, but I'm having trouble with there "about us" page. When you click on their profile it opens up a html iframe about their bios.
The current "about us" page
I have created sub pages for the bios in WordPress , but it keeps the current style of the site instead of the style that they have for the bios. What's the best path I could take to solve this problem? | So, if I understand your question correctly, your problem is that your iframes are showing the theme (nav menu, sidebar, etc.) and you don't want them to.
If that's the case, I'd recommend creating a new Page Template that is styled after your bio iframe (no menus, no sidebar).
There's more info on creating custom page templates here: < | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "theme development, jquery"
} |
Disable collapse of admin meta boxes
I have been attempting to disable the ability to collapse admin meta boxes. By the looks of it WordPress creates this functionality in postbox.js /wp-admin/js/ but I have been unable to find a hook or suitable JavaScript to overwrite the built in functions.
This is a some test code I am working with:
jQuery('.postbox h3, .postbox .handlediv, .hndle').bind('click', function(e) {
e.preventDefault();
return false;
});
Any thoughts on how this could be achieved? | Add this to your functions file and it will kill the metabox toggles:
function kill_postbox(){
global $wp_scripts;
$footer_scripts = $wp_scripts->in_footer;
foreach($footer_scripts as $key => $script){
if('postbox' === $script)
unset($wp_scripts->in_footer[$key]);
}
}
add_action('admin_footer', 'kill_postbox', 1); | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 2,
"tags": "jquery, admin, metabox"
} |
Create scroll of custom post types
I would like to create an area on an HTML homepage (HTML site that contains WP pages) that presents through an iframe or other, the titles of all posts for one custom post type. Any ideas would be greatly appreciated. | If you made the home-page of your site a WordPress page, you could just create a page-template for that home page.
Within that page template you could have all of your HTML, as well as the loops for showing your posts or pages or whatever else. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "custom post types"
} |
Query posts from category based on a filter most favorited
I have one question. I need to query posts from category based on the filter most favorited ( < ) which is placed in custom_sort.php to my index.php page
This is how the posts from categories are called ( < ) in index.php.
Is there any way to get the posts from category based on the most favorited filter?
Thank You so very much in advance :D | `query_posts` accepts custom query variable as arguments. So assuming that adding
?sort_by=most_favourites
to an url alters the sort order to sort by the most favourites (i.e. you've set `sort_by` as a recognised WordPress query variable, and setting it sorts the returned posts accordingly) then, try:
$args = array(
'cat' => $cat_lists[$i],
'showposts' => intval(get_theme_option_by('bn_list_per_item', 6 )),
'sort_by' => 'most_favourites',
'post_type' => 'post');
That should return the set number of posts from the category selected, in order of '`most_favourites`'.
**Update:**
To alter the the value of `sort_by` for category with ID 30 (say), put the following, after `$arg` and before `query_posts`:
if($cat_lists[$i]==30){
$args['sort_by']='most_commented';
} | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "categories, functions, filters"
} |
Disabling automatic teasers
I have a custom theme that displays the excerpt:
$data = get_the_excerpt();
if ($data) echo "<div class='excerpt'>$data</div>";
if nothing is entered in the excerpt field in the post editor, Wordpress will automatically use the auto-generated teaser.
I would like to get rid of this behaviour. Is there any way to do so? At the moment, I have to entere a space into the excerpt field of every post to prevent the automatic teaser from showing. | Try using `$post->post_excerpt` instead:
// globalize $post, just in case
global $post;
// find out if the post has a defined excerpt
$data = $post->post_excerpt;
// If so, output something
if ($data) echo "<div class='excerpt'>$data</div>";
This method will bypass the auto-excerpt generation inherent in `get_the_excerpt()`.
**EDIT**
By popular demand, the same code, using `has_excerpt()`:
// find out if the post has a defined excerpt
$data = ( has_excerpt() ? get_the_excerpt() : false );
// If so, output something
if ($data) echo "<div class='excerpt'>$data</div>"; | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "theme development, excerpt"
} |
WordPress Admin back-end - advanced options page?
Am I losing my mind? I seem to recall that somewhere in the Admin back-end there was a page that basically listed out all the fields within wp_options. Does this ring a bell to anyone else? I thought maybe it was a MU thing but it's not there either. At one point I seem to recall running into a page where you could edit the options directly (without using a DB client). No big deal if there isn't but I swear I've seen such a beast, and I don't think it was through a plugin... | // Adds 'ALL' options page - only accessible for admins and custom roles that have the 'manage_options' capability.
function wpse31956_all_settings_page()
{
add_options_page( __('All'), __('All'), 'manage_options', 'options.php' );
}
add_action( 'admin_menu', 'wpse31956_all_settings_page' );
Note: As I just saw that me an @ChipBennet posted at nearly the same time: The answer is the same. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 4,
"tags": "admin, options"
} |
Best Way to Setup a Network of WP Sites?
What, in your opinion, is the best way to setup a network of WP sites with a shared login?
* I want users to stay logged in to their account when they switch sites
* I want this to be used with different domains | What you're asking for is very easy with this plugin: < It does cross-domain cookie syncing with all of your sites on one Multisite installation.
I've used this a couple times and it works dandy. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": -1,
"tags": "multisite, login, domain mapping"
} |
why don't I get error messages in admin when developing?
I am curious as to why my screen goes completely blank when an error is present in my code. This only happens to me when it is an admin function.
No warnings, no syntax error messages, nothing. Just a blank screen. Which makes it really difficult to find the problem.
How do I get the errors to show up and how do I stop the blank screen?
Thanx in advance! | You need to add the following to your `wp-config.php` file:
// Enable debugging
define( 'WP_DEBUG', true ); | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 3,
"tags": "plugin development, admin, errors"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.