INSTRUCTION
stringlengths 11
999
| RESPONSE
stringlengths 0
999
| SOURCE
stringlengths 16
38
| METADATA
dict |
---|---|---|---|
Wordpress and Magento: let Wordpress manage user registration and logins?
I need to integrate Magento and Wordpress for a corporate website.
There will be other functionalities in the website that will require a login (ie forum, helpdesk and maybe others...) which I would like to develop with Wordpress since I'm totally ignorant at the moment on Magento and looks a very complicated system for theming and extending.
The problem is user registration and logins: which system should handle those? Wordpress or Magento? What would be the best route to follow?
Thank you so much for any help or advice | There is a plugin Mage Enabler < which makes Magento session available to WordPress, it's probably a good place to start. The author has written a couple of good posts on his blog detailing integrating the two. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "login, user registration, customization, shared user tables"
} |
Wordpress removes spaces in URL on pagination
I'm having a problem with wordpress rewriting my URLs, basically I have a regular search form with method set as `GET`, when I submit it the URL looks like this at first:
`
Wordpress adds the `+` symbol to separate the string and the results show fine, but when I click on the previous posts link the URL changes to:
`
Since the `type` parameter is now `MyVariable` it shows me no results, it doesn't matter if I type the `+` sign directly in the URL, when I press ENTER it just gets removed.
It seems to be related to how wordpress handles canonical URLs but I'm not sure about it, can anyone help me?
Thanks in advance. | I don't think this will solve your problem, but take a look at `url_encode()`.
$pagination['add_args'] = array('s'=>urlencode(get_query_var('s'))); | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 2,
"tags": "url rewriting, pagination, pages, redirect"
} |
Insert content into <title> head tag with function
Is there a hook available that lets you append or prepend text to the `<title>` tag in the head?
I've seen lots of posts about customizing the `<title>` tag, but they all involve manually adding a function inside the `<title>` tag. I'm looking to modify it with a hook if possible so it can be easily turned on/off in a functions.php file. | The content is modified with filters, not hooks.
To modify the <title>, use wp_title filter
Example:
add_filter('wp_title', 'set_page_title');
function set_page_title($orig_title) {
return 'Modified ' . $orig_title;
} | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "php, functions, title"
} |
Custom user role still showing up after deletion, ideas?
I previously created a new user role called "Owner" which worked fine, however I decided to delete it afterwards from my functions.php since I found it to not be as useful for my project after all...Odd thing is though, the new custom user role is still showing up in wordpress' dropdown menu where you assign a role to a user in the dashboard.
Any ideas whats going on here? I double checked my functions.php over and over and I deleted the function for sure so I have no ideas whats going on...My guess is its getting cached somehow but clearing the browser out makes no difference.
Best | You could try running this once in your `functions.php`
$wp_roles = new WP_Roles();
$wp_roles->remove_role("your_role"); | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "functions, user roles, users"
} |
Apply styles to blockquote element with the WYSIWYG editor
I have a blockquote and I can float it left or right if I want by going into the html editor and adding class="alignleft" etc. Is there any way I can make that available to a non tech individual with a button or plugin / function or something. I think i'm looking at a tinymce plugin but i've never done anything with that area; so hoping to avoid that at this time if at all possible. If that is what I need would anyone have a code snippit or a link to a good tutorial. I imagine it's a fairly common thing to have. | This tutorial gives you a short plugin you can modify to create a "styles" drop down with the "alignleft" and "alignright" classes in it.
As a note, just to stay out of WordPress's way, I might choose a different class or at least something prefixed like me-alignleft. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "plugin development, theme development, functions, css"
} |
Limit 'contributers' abilities in WordPress
I have a few custom post types which i don't want any contribute to view or touch. However, the default settings allows contributes to see these in their admin. How do i disallow contributes access to certain post types? | When you register your post type you can show/hide the UI in the arguments. I would approach it this way:
$allowed = current_user_can('administrator') ? true : false;
$args = array(
//other args
'show_ui' => $allowed
);
//register_post_type() function;
This will maintain the custom post type architecture while hiding the UI for those who are not administrators. For more information about Wordpress User Capabilities see this page: < | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "php, admin"
} |
Displaying a custom post type alphabetically
I've created a custom post type which now has around 100 posts in it. I simply want to display these in alphabetical order by the post title rather than the default which seems to be most recent first. I've tried various plugins and other solutions, but most only allow manual sorting (too many posts for that to work), I'm told that the code below should work but it seems to have no effect at all.
Any help appreciated.
<?php
$args = array( 'post_type' => 'tenant', 'posts_per_page', 'orderby=title&order=ASC' => 5 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?> | try this:
<?php
$args = array( 'post_type' => 'tenant', 'posts_per_page'=>5, 'orderby'=>'title','order'=>'ASC');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
You will find more info o custom queries here: < | stackexchange-wordpress | {
"answer_score": 8,
"question_score": 7,
"tags": "custom post types, order"
} |
Including inline Custom Fields info with add_filter in functions.php
I have a function set up to place some standard text in each post for a Custom Post Type. However, within that standard text I want to pull some unique text from a few custom fields. Not sure what is wrong with my code:
function default_content($content) {
global $post;
if ($post->post_type == 'my-custom-post-type') {
$content .= '<p style="text-align: center;"><strong>Custom Field Text here: <?php echo get_post_meta( get_the_ID(), \'custom-field-1\', true )</strong></p>
<p style="text-align: center;"><a href=" echo get_post_meta( get_the_ID(), \'custom-field-2\', true )">Link 01</a></p>';
}
return $content;
}
add_filter('the_content', 'default_content', 0); | You are trying to echo within a variable. You also have encapsulated PHP tags in the string as well. You need to concatenate just the functions themselves like this:
function default_content($content) {
global $post;
if ($post->post_type == 'my-custom-post-type') {
$content .= '<p style="text-align: center;"><strong>Custom Field Text here: '. get_post_meta( $post->ID, "custom-field-1", true ).'</strong></p>
<p style="text-align: center;"><a href=" . get_post_meta( $post->ID, "custom-field-2", true ).'">Link 01</a></p>';
}
return $content;
}
add_filter('the_content', 'default_content', 0);
Also you are calling global $post, so use $post->ID instead of get_the_ID().
Cheers! | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "custom field, functions, filters"
} |
"pre_get_posts" firing on every query
How can I change arguments for the main query only, and not affect other queries?
add_filter('pre_get_posts', 'custom_post_count');
function custom_post_count($query){
$query->set('posts_per_page', 5);
return $query;
};
Because this action is called inside the get_posts method of WP_Query, this code will alter the _posts_per_page_ argument for all loops, not just the main, so passing this argument to WP_Query is useless... | Basically what you are looking for is the **`global $wp_the_query`** variable which is set to the value of the main query. It may not be a perfect fit for 100% of cases but will probably work fine in 99% of cases:
add_action( 'pre_get_posts', 'custom_post_count' );
function custom_post_count( $query ){
global $wp_the_query;
if ( $wp_the_query === $query ) {
$query->set( 'posts_per_page', 5 );
}
return $query;
}; | stackexchange-wordpress | {
"answer_score": 7,
"question_score": 3,
"tags": "wp query, loop, pre get posts"
} |
Need help building a filter to edit the output of "image_send_to_editor"
What I'm trying to do is edit the output of `image_send_to_editor` so that i can make the anchor that wraps around the image have a specific **class** & **rel**.
I plan to basically make each image that gets inserted into a post become fancybox capable without having to be in a gallery or using a plugin.
Heres what I have thus far but I need help filling in the blanks...
<?php
add_filter( 'image_send_to_editor', 'fancy_capable', 10, 7);
function fancy_capable($html, $id, $alt, $title, $align, $url, $size ) {
// not sure what to do here???
return "$html";
}
?> | Your best bet here would be to use jQuery to grab any link that links to an image and tell it to use fanceybox.
jQuery(document).ready(function($){
$('a[href$="jpg"], a[href$="png"], a[href$="jpeg"]').fancybox();
});
If you want this to work just for your post content areas use this:
$('.post-content a[href$="jpg"], .post-content a[href$="png"], .post-content a[href$="jpeg"]').fancybox();
You will need to replace .post-content with whatever HTML parent element wraps the content area. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 3,
"tags": "images, filters"
} |
Painless way to track remote Git repo for Wordpress updates
I'm looking for a way to keep development instances of Wordpress up to date and under version control with Git.
Has anyone managed to the following?
* set up git to track a repo containing the Wordpress core files
* add the Wordpress repo to a project via a submodule or similar
* get the latest version of WP from within the project by updating submodules (or whatever)
Ideally you would just need to update the WP core files in one repository, and then upgrade other dev instances using a single git command.
Anyone? | Mark Jaquith maintains a git repo of WordPress, synced with the SVN every half hour.
<
He also describes how to work with WP in git here:
< | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 0,
"tags": "git, version control"
} |
blocking the admin section (but still using admin-ajax.php)
I am building a community based WP site at the mo and have blocked anyone bar admins from using the admin section on the site with:
add_action( 'init', 'sw_block_users' );
function sw_block_users() {
if ( is_admin() && ! current_user_can( 'administrator' ) ) {
wp_redirect( home_url() );
exit;
}
}
However, I'm also using the awesome power of admin-ajax.php to do a few ajaxy things (as outlined here : < which get blocked by the above function.
Is there a different way I can prevent non-admins from getting to wp-admin directory, while maintaining the use of the admin-ajax file? Thanks! | The following action hook should help:
add_action('admin_init', 'wpse28702_restrictAdminAccess', 1);
function wpse28702_restrictAdminAccess() {
$isAjax = (defined('DOING_AJAX') && true === DOING_AJAX) ? true : false;
if(!$isAjax) {
if(!current_user_can('administrator')) {
wp_die(__('You are not allowed to access this part of the site'));
}
}
} | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "wp admin, ajax"
} |
BuddyPress - Hook to Update Custom Profile Fields
I am working on custom app for a client that requires some extra fields in the user's profile. I have successfully created a registration page that saves the custom fields and now I need to do the same for the "Edit Profile" page. The function that I used to save the custom fields on registration is generic enough that I think I can use it for the update too. I cannot find the right hook to make it work, though. I have tried "profile_update", "edit_user_profile_update", and "personal_options_update" with no luck. Is there something that I am missing here? | After trudging through the BP source code today, I believe that I have finally figured this out. The hook used to update Profile Fields in BuddyPress is "xprofile_data_before_save". If anyone know of something better, please let me know! | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "custom field, buddypress, profiles"
} |
Page display certain Category Posts
I want to do almost exactly this: <
But Im confused by the last line:
> Save this to pageofposts.php and then assign PageofPosts as the Template when creating the action Page:
How do I tell Wordpress to go to index.php, (or anything else) when, for example, it receives an 'events' slug? | Read more on how to use page templates | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "categories, page template"
} |
How can I highlight admin comments?
Basically what I want is to have all comments posted by admins with different background color than the rest, so they're easily distinguishable.
I wasn't able to find any plugin that would do this though, and hacking it into the theme doesn't look very clean.
Any suggestions? | By default WordPress already adds user/admin/post author specific CSS to comments with the following three elements.
`#byuser`
`#comment-author-admin`
`.bypostauthor`
So you can just add something like `#comment-author-admin {background-color;blue;}` to your stylesheet. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 2,
"tags": "comments"
} |
Do I need to resize an image to fit the post?
I'm going to post an image in a blog post, first uploading the image to my server, and using its url.
If the image is bigger than the maximum width of my blog-post, will it take longer to download, or will WordPress squish the image for the space it has to fit?
If I need to make the image the right size to fit, what size? My blog is at <
Thanks, | You should use the built-in WordPress media manager to attach/insert images in posts. That way, if you define `$content_width` appropriately, WordPress will auto-resize `large` sized images to fit accordingly.
Otherwise, you'll have to rely on using CSS to set the `max-width` property for images within your content container (e.g. `#content img{ max-width: 500px; height: auto; }`
Outside of these two methods, WordPress _will not_ resize your image. If you insert an image in a post, and that image is wider than your content width, the image will overflow your content area. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "images"
} |
What is the Wordpress Pinecone sitting on top of?
Does anybody know where wordpress gets their banner images? Perhaps we could find the original photo? I'm curious just what exactly this pine cone is sitting on top of.
image | Header images come from Matt Mullenweg's photos <
It's unreal to find if it was posted anywhere with proper description (man snaps gigabytes of pics), go ask him. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 2,
"tags": "themes, images, headers, theme twenty eleven"
} |
Exclude Current Post from Recent Posts Loop
what would be the best way to exclude the current post I am viewing from this recent posts query. Thank You!
<?php
global $post;
if (in_category('top-lists')) {
$myposts2 = get_posts('numberposts=5&offset=0&category=7');
}
else if (in_category('playlists') || in_category('playlistall')) {
$myposts2 = get_posts('numberposts=5&offset=0&category=6,37');
}
else if (in_category('news') || in_category('news')) {
$myposts2 = get_posts('numberposts=5&offset=0&category=95');
}
else {
$myposts2 = get_posts('numberposts=5&offset=0&category=-6,-7,-37,-95,-177');
}
foreach($myposts2 as $post) :
?> | This the `post__not_in` arg should work dandy for you:
$args = array(
'numberposts' => 5,
'offset' => 0,
'category' => 7,
'post__not_in' => array( $post->ID )
);
$myposts2 = get_posts($args); | stackexchange-wordpress | {
"answer_score": 36,
"question_score": 11,
"tags": "get posts, exclude"
} |
How to edit/remove a term that's in multiple taxonomies?
Some of the terms on my site appear with the same exact slug, in multiple taxonomies.
For example: 'education' appears in both the 'department' taxonomy and the 'topic' taxonomy.
Now, I can't seem to modify or delete a term from one taxonomy without affecting the term in the other taxonomy.
* If I change 'education' to 'department-of-education' in the 'department' taxonomy, it changes to 'department-of-education' in the 'topic' taxonomy as well.
* If I delete 'education' from departments, it disappears from topics as well.
How can I separate the terms?
Wordpress does seem to prevent same-named terms in different taxonomies in the admin, but my taxonomies and terms were imported in the course of a site migration using a WXR file, and Wordpress let them in—so now I'm stuck with them. | As it turns out, though terms could not be _edited_ without affecting all instances, they _could_ be deleted without deleting all instances.
So, it looks as though the answer is this:
* you **_cannot_** separately edit a term that's in multiple taxonomies, but
* you **_can_** remove that term from a taxonomy without removing it from the other taxonomies it appears in.
For related ideas, see < | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "custom taxonomy, terms, slug"
} |
Make 'Page' slug the 'index'
I want to have my Index page show posts from a certain Category ('news'). I have that functionality, but is there a way I can make a 'News' Page, where the slug just points to the index? | I would take the current code you have and drop it into a page template called tpl-news.php or whatever you choose. Add the following to the header before your index.php code:
<?php
/*
Template Name: News
*/
//Add your index.php code here
//You can also use wp_redirect(home_url()) here as well if I misunderstood your question
Now, create a page called 'News' with a slug of 'news' and select the 'News' page template. That should do the trick for you.
I would also look at how Wordpress template hierarchy works and build template files that target a specific category - Example: category-news.php would force this file to be used when the 'news' category permalink is viewed rather than the default archive template.
< | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "posts, frontpage"
} |
Will the following code make my css deal with images in the optimum way?
In Appearance/Editor, the Stylesheet for my theme has in it the following code:
#content img {
margin: 0;
max-width: 640px;
}
#content .attachment img {
max-width: 900px;
Does this mean that if I use the 'Add an image' button in WordPress, and then pick 'From url' to post an image in a blog post, that if the image at the url is bigger than the maximum width of my blog post, that it will not matter? -- That it won't result in the image taking longer than otherwise necessary to load on the users computer? | **No, the size of the source image still matters.**
**The rule only means that the image will not display wider then that.**
It is there mainly to prevent the large images from breaking the layout.
This will have no effect on the download time (browser is loading the original image anyway) and you are actually making browser do some little extra work to resize the image. Also different browsers will handle this task differently so be sure to check how your images look if they are being heavily browser-resized.
Further discussion and workarounds are out of the scope of this site. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": -1,
"tags": "css"
} |
Problem with JWplayer. Video is missing?
Firstly, I am new at using video with wordpress. I have installed the jwplayer plugin and using this bit of code to show the video player on the page.
$video_array = explode("\r\n", stripslashes(extra_option('video_links')) );
foreach($video_array as $vid){
if (!empty($vid))
echo jwplayer_tag_callback("[jwplayer config=\"Homepage Player\" file=\"$vid\"]");
}
**Note:**
"Homepage Player" is a custom config i made form the jwplayer plugin option page.
**Problem:** You can see the site here < There are four video to show. For the first three the player isn't showing and the last one player is showing but you can only hear sound but no video :( | When you work with jwplayer you need to make sure you-
1. Check the supporting file documentation <
2. If you are using anything other than mp4 its fine.
3. If you are tying to play mp4 files and you are having problem with it (video not playing before it fully loaded) you must swap the index of the mp4 files using this app <
I think that all you will be need to start with jwplayer. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "videos, jwplayer, video player"
} |
How can I get list of emails of users who commented on a post?
What I want here is simple, but I'm not really sure how to approach it. I have a tournament website based on WordPress, where users sign up for a tournament by commenting on a post.
The problem is, that then I need to send all those guys an email, which means I have to look up 50+ emails for users every single time. I'm thinking of doing some kind of JOIN on the comments and users tables, but I don't really know how to put this in WordPress.
I read somewhere, that if I want to add stuff for users, it should be in a theme, and if I want to add it for administrators, it should be as a plugin, but this looks like it could be a simple script put somewhere.
How would you solve this? | global $wpdb, $post;
$query = sprintf("SELECT comment_author_email
FROM {$wpdb->comments}
JOIN {$wpdb->posts} ON {$wpdb->posts}.ID = {$wpdb->comments}.comment_post_ID
WHERE comment_post_ID = %d
AND comment_approved = '1'",
$post->ID);
$emails = $wpdb->get_col($query);
$emails = array_unique($emails);
// your e-mails
print_r($emails);
You can also use the built-in `WP_Comment_Query` (or get_comments), but it's going to be a little slower... | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 0,
"tags": "comments, users, email"
} |
Plug-in that shows x number thumbnails from another post
I am building a blog where the posts of a certain category make up image galleries (using the standard WP functionality and a modified single.php to display the gallery.)
Now, I would like to add links to some of those galleries inside other blog posts. The ideal way would be a shortcode like
[thumbnails galleryid=209]
(or whatever) that displays a definable number of thumbnails from post no. 209, and links there.
Does anybody know of a ready-made plugin that does this? | I don't think so, but you could use get_children and get the attachment(s) of those posts:
$attachments = get_children(array(
'post_parent' => $post->ID, // <- source post
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => 'post_date',
'orderby' => 'DESC',
'numberposts' => 5, // the number
));
Then get the image URLs:
$size = 'post-thumbnail'; // or whatever size you need
foreach($attachments as $att){
list($source, $width, $height) = wp_get_attachment_image_src($att->ID, $size);
// echo '<img src="'.$source.'" width="'.$width.'" height='".$height."' />';
} | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "plugins, plugin recommendation, gallery"
} |
Pass var into wp function instead of direct string text
Looking to replace static string text in this function with dynamic text from a var.
Current model:
comments_number( 'no responses', '1 response', '% responses' );
Ideal Outcome (code guess):
comments_number( '$no_responce_text', '1'.$responce_text, '%'.$responce_text );
I am sure this is an easy php question but stumped here.
Any help would be nice.
Thanks | This should do it:
comments_number(
$no_responce_text,
sprintf('1 %s', $responce_text),
sprintf('%% %s', $responce_text)
);`
Use get_comments_number if you want it properly localized. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "variables"
} |
How can I offer different RSS-Feeds by category?
I want to write a WordPress-Blog about some quite different topics. I will write most of it in English, but some topics are only interesting for Germans. The posts in the German-category will be in german. I guess it's not interesting for most readers who read the English categories whats in the German category.
So I would like to have one RSS-Feed for all posts in the German-Category and one RSS-Feed for all other posts. How can I realise this?
Per default are two Feeds available:
<link rel="alternate" type="application/rss+xml" title="MyBlog RSS Feed" href=" />
<link rel="alternate" type="application/atom+xml" title="MyBlog Atom Feed" href=" /> | I just saw that WordPress (or any plugin I've installed) makes this by default. Just go into your category and take a look at the feeds. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "categories, rss"
} |
How to list first (etc. 5) posts as new?
I am looking for a plugin or a way to list first five posts as new. It should be just a small picture added in the index.php. Any ideas of how I could achieve this? Thanks! | This is pretty easy.
//Include this above your loop
$i = 0; //Counter
if(have_posts())while(have_posts())the_post();
//include this in your loop
$i++;
if($i <= 5)
echo "<img src=' alt='Image Title' />";
//Stop including in your loop
the_title();
the_content();
endwhile; else:
endif; | stackexchange-wordpress | {
"answer_score": 0,
"question_score": -1,
"tags": "posts"
} |
Common page width?
I just made a new wordpress theme for a code type site, I am currently at 920px wide, I am curious what most people are using for a width now days, I would like to go wider but I just want to know if there is any kind of standard or common width that most people use? | A width of 950-960px should be ok for most screen resolutions. Css Frameworks/Libraries like blueprint, 960gs, etc. use the same width. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "css"
} |
$page = get_page_by_title CONTAINS
Just wondering how to fetch a page by using 'title contains'. I can retrieve a page by using the following
<?php
$page = get_page_by_title('Restaurants and Pubs');
?>
but how could I do 'page title contains "Pubs"'?
Thanks | You should build a query using the Wordpress database class. Place this in your functions.php file
function get_page_by_title_search($string){
global $wpdb;
$title = esc_sql($string);
if(!$title) return;
$page = $wpdb->get_results("
SELECT *
FROM $wpdb->posts
WHERE post_title LIKE '%$title%'
AND post_type = 'page'
AND post_status = 'publish'
LIMIT 1
");
return $page;
}
Use this in your theme:
$page = get_page_by_title_search('Foo Bar');
echo $page->post_title;
echo $page->post_content;
//etc... | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "pages"
} |
Custom menu deletes itself
I've set up a menu on one of my sites. The menu has ~30 items. Everything is fine, but at some point the menu crops itself and displays only the first 12 item. Does anyone have an idea why this is happening and how to tackle this issue? | Not sure it will help, but here is sort of what you are talking about: <
Try adding:
suhosin.post.max_vars = 5000
suhosin.request.max_vars = 5000
to your php.ini | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "menus"
} |
Does wordpress have a post hit counter?
Is there anyway to show in a template for a post, how many times that post has been viewed, like hits without some sort of plugin? It seems wordpress would have this built in, but I am unable to find any template tags for such a think in the documentation? | Not in core. You can use post meta to store this information on page loads. If you have caching plugins enabled, you might want to increment the hit counter with an AJAX call, otherwise you can just add this directly in your single.php and page.php templates:
//Add to functions.php
function get_hits(){
global $post;
$hits = get_post_meta($post->ID, '_hit-counter', true);
return $hits;
}
function update_hits($count){
global $post;
$count = $count ? $count : 0;
$hits = update_post_meta($post->ID, '_hit-counter', $count++);
return $hits;
}
//Usage within the loop
update_hits(get_hits()); | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 4,
"tags": "plugins"
} |
Fatal error when using '#' character as an admin menu link title
When I try to title an admin menu link `#` or `#`, I get a fatal error before the admin menu is loaded:
> Fatal error: Cannot access empty property in /path/to/wp-includes/class-wp-admin-bar.php on line 79
The error does not occur if I use an alphanumeric menu title like `My admin link`. This is the code I am using in functions.php:
function my_admin_bar_menu() {
global $wp_admin_bar;
if ( !is_super_admin() || !is_admin_bar_showing() )
return;
$wp_admin_bar->add_menu( array(
'title' => __( '#'),
'href' => admin_url('myurl.php')));
}
add_action('admin_bar_menu', 'my_admin_bar_menu'); | I figured out the problem: You must specify an ID in the add_menu array if the title is not alphanumeric. So, this code worked:
function my_admin_bar_menu() {
global $wp_admin_bar;
if ( !is_super_admin() || !is_admin_bar_showing() )
return;
$wp_admin_bar->add_menu( array(
'title' => __( '#'),
'id' => __( 'my_menu_item'),
'href' => admin_url('myurl.php')));
}
add_action('admin_bar_menu', 'my_admin_bar_menu');
The only change is the addition of the line containing 'id'. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "admin menu, fatal error"
} |
Controller functionality - if user is not logged in send them to specific page (not wp_login)
This sounds dead bang simple, but I just can't figure it out.
I want the following functionality:
_If user is not logged in and they try to access anywhere on the site (including the homepage) - send them to a specific page._
I tried, adding the following but received a "not redirecting properly" message:
if (!is_user_logged_in() ) {
wp_redirect ('/public' );
exit;
}
I guess if I can add a clause to the if statement saying and the page I am accessing is not the public page, but I'm not quite sure how to that properly.
Any plugins that I see out there redirect to the wordpress login screen.
Any help is greatly appreciated!
Thanks,
MG | The reason why you are getting a `not redirecting properly` message is because you are creating an endless loop of redirects. They get redirected to `/public` but because they are not logged in they get redirected again and again and again...
Try this code instead:
if( ! is_user_logged_in() && ! is_page("public") )
{
wp_redirect( site_url("/public") );
exit;
}
I'm assuming that `/public` is a page you have setup. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 2,
"tags": "wp redirect"
} |
How can you make permalink work for custom post type and taxonomy?
I have spent days now trying to figure this out, StackOverflow is my last resort. All I want is the following:
<
For posts this is insane easy, just adding /%category%/%postname%.html as a permalink does the trick. However for custom post type this seems insane tough.
I have a registered post_type **project**. And a taxonomy **project_category**
Now I like my permalinks to turn out as
/project - Overview of projects in all categories.
/project/CATEGORY - Overview of projects within that category.
/project/CATEGORY/SUBCATEGORY - Overview of projects within that subcategory.
/project/CATEGORY/SUBCATEGORY/postname - The actual post.
Probably wp_rewrite needs to help me out here tho I have no clue how. Can anyone help me out? | I've just gotten my head around Doing something similar. This is adapted from this tutorial
1. For your post type registration make sure that query_var, publicly_queryable, and has_archive are set to true and rewrite is set to false.
2. Next up is the code here.
Edit: sorry, but code hinting is completely not working for me today. Code is in above link | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 3,
"tags": "custom post types, categories, taxonomy"
} |
url rewrite .htaccess extension to permalink
I have a custom page and template, that I'm passing a query-string to. It has a wordpress permalink like so
/mypage/
I want to be able to add another rule so that the permalink receives a slug
/mypage/this-slug
is rewrote to
/mypage/?myslug=this-slug | This should work for you-
function wpse28906_rewrites_init(){
add_rewrite_rule(
'mypage/([^/]+)/?$',
'index.php?pagename=mypage&myslug=$matches[1]',
'top' );
}
add_action( 'init', 'wpse28906_rewrites_init' );
function wpse28906_query_vars( $query_vars ){
$query_vars[] = 'myslug';
return $query_vars;
}
add_filter( 'query_vars', 'wpse28906_query_vars' );
You can then use `get_query_var( 'myslug' )` in your template to get your slug value. Don't forget to flush your rewrite rules after adding this by visiting the permalinks settings page. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 0,
"tags": "permalinks, htaccess"
} |
add_filter the_content str_replace after shortcode
I want to add a PHP `str_replace` to the `add_filter('the_content')` function. I believe my problem is that the shortcodes are loading after the `str_replace` is called.
I have a shortcode that outputs a form, i want to make it that in all HTML form tags, the attribute `autocomplete='off'`.
Heres the code i have.
add_filter('the_content', 'disable_autocomplete');
function disable_autocomplete( $content )
{
return str_replace('<form', '<form autocomplete="off"', $content);
}
Any ideas? | You can change the priority of actions and filters, it's the third argument of `add_filter` (and `add_action`) and it defaults to 10. So change it to a high number and have your filter fire way after the shortcodes and other stuff are inserted.
<?php
add_filter('the_content', 'disable_autocomplete', 99);
function disable_autocomplete( $content )
{
return str_replace('<form', '<form autocomplete="off"', $content);
} | stackexchange-wordpress | {
"answer_score": 6,
"question_score": 5,
"tags": "php, html, forms, autocomplete"
} |
Where is a custom post type's "description" surfaced in WordPress?
Note that this is not a question about how to change / edit a CPT's description. It's more about "why the heck is it provided?" because I haven't found anywhere either in the Admin back-end or the front end, where this description is actually shown.
What am I missing? | There's not really a good usage of the description in WP. However, if you wish to extend the Wordpress functionality and use the description in your theme or plugins, it's available to you with the following:
global $wp_post_types;
$post_type = 'my_cpt';
$description = $wp_post_types[$post_type]->description; | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 7,
"tags": "custom post types"
} |
Execute Shortcodes when submitting post
I'm using shortcodes to insert some image links to my posts I grab from XML files (by an ID). As this needs to be executed just once it's not necessary to this everytime a user loads the page. So how can I replace the Shortcode with the needed content as soon as i save/publish/update the page? | That's not how shortcodes work. Shortcodes are meant to be interpreted whenever the page is rendered - they're used when WordPress _filters_ the page/post content.
What you're looking for is a content template. A tag the user can add to the page that will be converted into something else when the post is saved, like an RTF tag in a mail merge.
There's a filter that's run before posts are inserted into the database: `wp_insert_post_data`. This filter will pass the data for the to-be-inserted post as an array. You can take that array, parse your custom tags into whatever content you need, and pass it back before it's saved to the database.
Just filter `$data["post_content"]` and `$data["post_content_filtered"]` to make your replacement before passing the `$data` array back. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "shortcode"
} |
including post-specific feed without full wp_head()
I'm not including the wp_head() call in my header.php, but I would like to include the feed links for each post.
Is it possible to call wp_head() with arguments only to include specific functionality? Or alternately, can you call specific functionality (admin toolbar css, feed links, etc) directly? | all `wp_head()` does is run all the actions attached to it:
function wp_head() {
do_action('wp_head');
}
you can call `get_feed_link()` directly.
however -
it's important to note you're going to break most plugins by not calling `wp_head()` a better route may be to just `remove_action` on all the things you _don't_ want in `wp_head()`. look in `wp-includes/default-filters.php` for all the actions attached to it. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "theme development"
} |
How to disable multiple thumbnail generation?
Tried setting the thumbnail size, but left medium + large to 0 0 to disable them, still all 3 were generated. Is there anyway to selectively disable these via functions.php? | You can disable the medium and large image sizes by using the 'intermediate_image_sizes' filter:
function remove_image_sizes($image_sizes){
foreach($image_sizes as $key => $size){
if($size == 'large' || $size == 'medium')
unset($image_sizes[$key]);
}
return $image_sizes;
}
add_filter('intermediate_image_sizes', 'remove_image_sizes', 12, 1);
This skips adding these sizes and the options to insert a medium/large image are left blank in the media item. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 2,
"tags": "thumbnails"
} |
Plugin Recommendation for selling one page content
Hi I need a recommendation for a plugin, preferably free, that enables me to block a page's content. I only need this for a few pages, and the users must be able to buy the content on an individual page basis. Thanks | I would use a membership plugin such as:
1. WPMU Dev Membership - <
2. Wishlist Member - <
I've personally used both and they work great.
With these plugins, you would setup a membership level specifically for each page content you wish to sell. You can do one-time or recurring payments for your content as well. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": -1,
"tags": "plugins, membership"
} |
Show image in excerpt post. Image not displaying
I am editing a costum theme. I was trying to add excerpt to the homepage. The homepage is costum.
The excerpt show just fine but the image refuses to be displayed it seems.
This is my code:
$args = array( 'numberposts' => 5, 'category' => 3,4,5,6,7 );
$posts = query_posts( $args . '&orderby=date&order=desc' );
foreach( $posts as $post ) : setup_postdata($post); ?>
<li>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div class="postcont">
<?php
echo get_post_meta($post->ID, "Thumbnail", true);
the_excerpt(); ?>
</div>
</li>
<?php endforeach; ?>
This is of course added to functions.php
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
}
Any toughts? | If you add support for Post Thumbnails, you can use its own function instead of `get_post_meta()`, see codex for more information - <
Use following code in your theme:
<div class="postcont>
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
the_excerpt();
?>
</div>
**EDIT**
And using the OP's code:
$args = array( 'numberposts' => 5, 'category' => 3,4,5,6,7 );
$posts = query_posts( $args . '&orderby=date&order=desc' );
foreach( $posts as $post ) : setup_postdata($post); ?>
<li>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div class="postcont">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
the_excerpt(); ?>
</div>
</li>
<?php endforeach; ?> | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "excerpt, thumbnails"
} |
How can you change the permalink for pages?
When I set my permalink to '/%category%/%postname%.html' this will work for all the posts, but the pages still don't have a .html at the end. Is there a way I can fix that? | Here's a very basic plugin that does just that: .html on Pages | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "categories, pages, permalinks"
} |
Best Way to Display Posts by Tag (not category)
I've been researching this, but there are so many choices I'm confused.
What I would like to do is display two loops on a static page that:
1. the first loop displays all posts with the tag "featured"
2. the first loop displays the thumbnail as well
3. the second loop displays all other posts, excluding the ones already featured
There seems to be many options, some wrong, some seemingly too complicated.
Is there a best practice for doing this?
Thanks! | 1. Query first set of posts (probably with `get_posts()`, unless you feel up to using `WP_Query` directly).
2. Loop through it, display, save their IDs in some variable.
3. Loop through them again, display thumbnails.
4. Query second set of posts, excluding IDs saved earlier via `post__not_in`.
5. Loop through it and display. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "post thumbnails, loop"
} |
How to set back-end language per user?
I would like to use the english interface for the back-end but I would like to set it to native language for an editor. I know WPML has this feature, but I don't want to install the unsupported WPML just for this reason.
What I am looking is a tiny plugin which gives a switchbox for the user profile page for setting the back-end language. Is there such a plugin? | Have you seen <
I think it does exactly what you are asking.
Also 'interesting' is < which attempts to set the locale automatically based n browser settings. | stackexchange-wordpress | {
"answer_score": 7,
"question_score": 9,
"tags": "plugins, admin, multi language, user interface"
} |
Sidebar not displaying on custom-page.php
Ok, I registered a new sidebar and have added some functionality to my theme so you can choose which sidebar to display from the back-end (using meta fields). It's working on all pages, except on a custom-page.php I created.
I've tried just about anything and can't get my head around why my selected sidebar isn't displaying on page.php (default sidebar is displaying), but not on custom-page.php. I might be overlooking something minor, but for now it's doing my head in. Any help would be greatly appreciated. | Found the solution. I forgot to add wp_reset_query(); which should always be added when using custom queries. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "sidebar, page template"
} |
In Wordpress, how do you make several different editors for a single page?
I have a homepage that has many different parts to it. So a s single editor can get convoluted very quickly.
Is there a way to break it up so that many editors attribute to this single page?
If so, what's your technique? | For this you should use this plugin: <
It will enable you to specify any kind of content for a given post or page. This new version already uses wordpress custom post types. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "php, cms"
} |
'Was this post useful' plugin
I'm searching for an FAQ plugin, which should have 'was this post useful' option (it can be implemented as a set of plugins as well, not necessary to be all-in-one plugin). Generally FAQ can be implemented as category with posts, but I'll need expand/collapse JS only in that category, and I need the 'was this post useful' option only in that category as well, so I prefer a plugin for it.
Any suggestions?
_Wordpress version: 3.2.1_ | Anyway Feedback provides this functionality. It can be enabled per post type, so I've registered custom post type, enabled the feedback for this post type, and registered the category taxonomy, so I can post FAQ questions in any category. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": -1,
"tags": "plugin recommendation"
} |
Disappearing Widget Text area
I recently encountered a strange thing for the first time with Wordpress...all of my text boxes in every widget sidebar disappeared! Other widgets are still there. Has this happened to anyone else? I am using 10 different sidebars on 10 different templates and all text widgets have failed. Is there a limit to how many sidebars you should have? What else could be the problem? | I decided to use Widget Logic instead of so many sidebars and that seems to have at leat circumvented the issue. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "sidebar, widget text"
} |
Disallow user from editing their own profile information
I'm currently developing an intranet and I am using Justin Tadlock's Members plugin to control roles and capabilities.
I have created a `HR` role to allow Human Resources staff to create and edit user accounts. All staff created in WP are given the `contributor` role with a select few members of staff given `editor` and `administrator` roles.
What I want is to stop staff from logging in and changing their own profile information. Only staff of the `HR` role should be able to edit profile information. | Worked it out with a bit of time. Here is the code I am using:
<?php
/*
Plugin Name: Restrict User Editing Own Profile
Plugin URI:
Description: Restricts users from editing their own profile information.
Author: Scott Cariss
Version: 0.1
Author URI:
*/
add_action( 'admin_menu', 'stop_access_profile' );
function stop_access_profile() {
remove_menu_page( 'profile.php' );
remove_submenu_page( 'users.php', 'profile.php' );
if(IS_PROFILE_PAGE === true) {
wp_die( 'You are not permitted to change your own profile information. Please contact a member of HR to have your profile information changed.' );
}
}
?>
The above code stops anyone from editing their own profile information despite who they are. People who have the ability to create and edit uses can still do so but cannot alter their own. | stackexchange-wordpress | {
"answer_score": 8,
"question_score": 10,
"tags": "login, user roles, profiles"
} |
activate custom sidebar widgets
Hey guys I'm trying to activate a sidebar for wp widgets.
So my HTML looks like this:
<aside id="leftSidebar">
<section>
<h3></h3>
<div class="contents"></div>
</section>
</aside>
So I want to put the widget inside "contents" and its title in h3 tag. How my activate function should be and what php to put in my html if needed? I didn't find any examples near mine so I appreciate any help 10x a lot in advance. | **You would register the sidebar in the functions.php file with something like this:**
<?php
register_sidebar(array('name'=>'custom-content',
'before_widget' => '<section>',
'after_widget' => "</section>",
'before_title' => '<h3>',
'after_title' => "</h3>"
));
?>
**And Use it in your theme like this:**
<div class="contents">
<?php if ( function_exists(dynamic_sidebar(1) ) ) : ?>
<?php dynamic_sidebar(custom-content); ?>
<?php endif; ?>
</div> | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "widgets, sidebar, register sidebar"
} |
what template-part to call, to have my post in the center of the page?
i was wondering if you could help me : i would like to change the center of my page only with my posts : (all my posts will be in the same category) : how can i construct the page :
so : 1.my menu in header.php
2.a single post in the center of the page
3.and the bottom div in footer.php, which contains the menu for the posts
i'm wondering, if n°2 is "index.php", what page should i call? for example in twenty_ten, they call "content" in index.php :
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
how can i proceed, if i would like to click on n°3 menu, and have a new page with the post in the center of the page? Do you know what i mean?
Thanks if you can be of any help | In the Twenty Ten theme they are using a file called loop.php. It defines the loop for different page templates and defines theme accordingly inside loop.php. That's what allows them to use get_template_part.
Depending on your theme and how it's set up will determine how to go what your asking. If all of your pages or single posts will show only one post or one page's content you could use CSS to control the output so it was a centered block on the page when displayed.
If you wanted to use a centered single post template and normal layout on other pages, you could assign a custom class to the page you want centered by using an existing page template or by creating a custom template and assigning the pages to that template inside of the page editor.
There are several different options. If you have additional info I might be able to be more specific on "How To". | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "posts, loop, get template part"
} |
How to remove "Taxonomy name:" from wp_title
The wp_title-generated `<title>` in my custom taxonomy archive pages contains the singular taxonomy name with a colon. I can't figure out where this is coming from (or if it's default Wordpress behavior), and I'd like to remove it. For example, in the archive page for the term 'Vanilla' in a taxonomy called 'Flavors', the `<title>` is
> Flavor: Vanilla | My Site Name
What I would like the title to be is simply
> Vanilla | My site name
The code in header.php is this:
<title><?php wp_title('|', true, 'right'); ?></title>
There's only one function in functions.php that's hooked into wp_title, and it looks unrelated to the Taxonomy name. I can't figure out where this is coming from or how to remove it.
How can I remove this?
(The answer in How to remove parent taxonomy name from the title generated by wp_title()? is not generalizable to this, and I'm guessing there's a more direct way to do it.) | Use `wp_title` filter to control output
function mamaduka_remove_tax_name( $title, $sep, $seplocation ) {
if ( is_tax() ) {
$term_title = single_term_title( '', false );
// Determines position of separator
if ( 'right' == $seplocation ) {
$title = $term_title . " $sep ";
} else {
$title = " $sep " . $term_title;
}
}
return $title;
}
add_filter( 'wp_title', 'mamaduka_remove_tax_name', 10, 3 ); | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 4,
"tags": "custom taxonomy, filters, title"
} |
Auto Changing Text Case
So I'm using all static pages and I specify that in my WP settings. When I specify what the 'Front Page' should be it turns my link in to Title Case instead of all Capital Letters like I would prefer. I have set in all caps in the title of my page so I'm not sure why it is converting it or how to stop it from converting it.
I'm using the default 'twenty eleven 1.2' theme not sure if it has something to do with that or not. Can somebody help me please? Here's a link to what I'm talking about.
< | I suspect that the problem is that you're using the default, fallback navigation menu instead of a defined, custom navigation menu. (The "Home" link you're seeing is the default home link output by `wp_page_menu()`.)
Go to **Dashboard -> Appearance -> Menus** , to define and apply a custom navigation menu. By applying your static front page explicitly, the custom nav menu item will use Post Title, rather than the default "Home" text being used by the default "Home" link output by `wp_page_menu()`.
Alternately, you could apply some CSS:
#access li {
text-transform: uppercase;
} | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "permalinks, pages, navigation, theme twenty eleven, customization"
} |
Modify my code - which takes the first sentence of the post and use it as a h2 tag - to work outside the loop
My code takes the first sentence of a post and places it's content inside a variable. The problem is it works only inside the loop.
I need help making this code outside the loop, becouse I want to use the posts first sentace as description in the header.php
Here it is:
<? ob_start();
the_content();
$old_content = ob_get_clean();
$content = strip_tags($old_content);
$match = null;
preg_match('/(.*?[?\.!]{1,3})/', $content, $match);
$first_sentence = $match[1];
$the_rest = substr($content, strlen($first_sentence));
if ( $first_sentence != '' && $the_rest != '' ){
echo '<h2>'.$first_sentence.'</h2>';
echo '<p>'.$the_rest.'</p>';
} ?>
One more thing, it would be perfect to keep the posts formating in this code. Any ideea how I can do that?
Ty very much, take care! | To get post info outside the regular loop, you can use `WP Query` Reference
In your example you can try something like;
$firstsentance = new WP_Query();
$firstsentance->query('posts_per_page=-1'); // add additional query parameters as needed, this will query all posts
$old_content = the_content()';
//do your php stuff here
endwhile; | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "loop, terms"
} |
Is there a way to make a custom Page type?
In a theme I'm building, there are two main types of page. One is a product-gallery, one is for general info. I'd like to use `wp_get_pages()` or `wp_list_pages()` twice in the sidebar, one with a list of one type of page, and one with the other.
I don't want to hard-code `include` or `exclude` in either list, as I can't predict which page IDs will be which type of page. So I'd like to do something like:
> wp_list_pages('type=gallery')
and
> wp_list_pages('type=page')
What technique should I be using here? | Create a hierarchical custom post type, then pass `post_type` to wp_list_pages:
$args = array(
'post_type'=>'gallery'
);
wp_list_pages( $args ); | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 3,
"tags": "custom post types, pages, wp list pages"
} |
Form Data Causes "Page Not Found"
If you go to < and select 2012 from the drop down menu in the years list, you will be taken to a 'page not found' page. But if you select any other year, or any other option in the drop down menus, it performs the search correctly.
Has anyone ever experienced this before, or know why this is happening?
Thanks in advance. | Change $year to another variable. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "search, query"
} |
Can I attach an image to a different post?
Image galleries display those images that were uploaded to that post, by default. If I wanted to move an image to a different post, so it appeared there instead, would I have to delete and re-upload? Or, is there a way to re-assign an image that's already in the Media Library? | This works for me: <
I've saved this as a snippet in my IDE for use in projects. Very handy! | stackexchange-wordpress | {
"answer_score": 6,
"question_score": 1,
"tags": "gallery, images, media library"
} |
Wordpress gallery shortag
I'm creating a simple slideshow on the side where i want to show 4 images from a post, i searched around i found this code that simply uses the build in gallery function
<li><?php echo do_shortcode('[gallery id="'.$post->ID.'"]'); ?></li>
the problem is that it spits out the entire gallery... is there noway to limit this to 2,3 ?
i tried to use
<
but for some reason, i didnt work... I guess it because all my posts are made of is a gallery of images
all help is appreciated regards | There is no way to limit the gallery query in the shortcode_gallery function. However, you can get the child attachments of a post using the following.
$attachments = get_children( array('post_parent' => $post->id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'numberposts' => 5) );
You will need to iterate through the attachments and build out your gallery HTML. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "php, gallery"
} |
Only display custom field if it there is a value inside
Quite a simple question really, but unsure how to do it. I have this little bit of code:
<li><span>
<?php if ( function_exists('get_custom_field_value') ){
get_custom_field_value('Essential info 5', true);
} ?>
</span></li>
...and I want to find out how I can adjust it so that if that particular field is empty, it does not display the list item at all.
Thanks! | use empty function to check if the return value is empty or not:
<?php if ( function_exists('get_custom_field_value') ):
$custom_field_value = get_custom_field_value('Essential info 5', true);
if(!empty($custom_field_value)):
?>
<li><span>
<?php echo $custom_field_value; ?>
</span></li>
<?php
endif;
endif; ?>
also check if the function 'get_custom_field_value' is returning with echo statement, you may need to change that to just return the result and not to echo it out.
Hope it solves your problem. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "custom field"
} |
Google map that plot's several markers - each one with custom data
I'm looking to create a custom Google map that plots several markers on it that then shows custom data in the popup when the marker is clicked.
I've setup the pages in WP in this manner:
Map (parent page)
* Company one (child)
* Company two (child)
* Company three (child)
...and so on.
I want the map to be on the map page and each marker to be of the child pages.
I use this plugin to create custom fields as it allows me to easily create the 20 or so fields (each one consists of various checkboxes, drop downs, image fields etc etc) per page.
**How would I loop through each child page and plot the marker based on their post code?** | I've done something similar using gmaps ( You might want to take a look at that. It's self explanatory and there's quite a bit of documentation IF you google around. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "custom field, google maps"
} |
Does anyone have the Custom Post Permalinks plugin from John P. Bloch?
Can you upload it somewhere or send to my email? | You can still find the most recent version in WordPress.org's plugin Subversion. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": -1,
"tags": "plugins, posts, customization, permalinks"
} |
In a url where Category Id is wrong It is showing wrong it is going to the page not found page
In my one project I am using old 2.8.4 version of word press. So If In url wrong category name is there then it is going to the page 404 page not found. But I want that still it should go to the archive page only.
In latest version of wordpress it is like that only. It is going to category page if i specify wrong category name then also.
So why it is not the case with old version what should do to go on the same page weather right category is there or wrong category is there. | You should really upgrade to the latest version. If you won't do that then simply copy your archives.php and paste it into the 404.php file. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "categories"
} |
How do WP know an image is a post thumbnail
What is stored in the WP database to let WP know I uploaded an image as a post thumbnail? I'm looking at the wp_posts table but I can't find anything. | It' stored in the post meta table as `_thumbnail_id`.
The thumbnail is actually a "post" entry too, I think it's stored as an "attachment" post type. So the `_thumbnail_id` meta value will be the ID which points to that attachment. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "post thumbnails"
} |
Extract Information from post content (using regex?)
I'm trying to replace some custom strings in my content before saving the post. I have got the $data["post_content"] which includes strings like %replaceContent:{type}% . Now I need to extract that string, read the {type} and replace the string afterwards depending on what's inside of {type}. I imagine this would best be done using regex, unfortunately I don't really know how to go about this. Ideas? | This belongs to stackoverflow. Here's a solution anyway:
$content = preg_replace_callback('/\%replaceContent:{(.*?)}\%/', 'do_replacements', $content);
function do_replacements($matches){
$type = $matches[1]; // here's your {type}
$replacement = "...replacement for {$type}";
return $replacement;
} | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "plugin development, content, regex, customization"
} |
Add field to all custom post types
I know how to add fields to custom post types one at a time.
I was wondering if there is a way to add a field to the default post type as well as all the custom post types at once?
Thanks | You can't use the `add_meta_box()` function with an array of post types unfortunately although it would be a good core contribution.
The way to do this at the moment is to get an array of your post types and loop over them calling your `add_meta_box()` line for each one eg:
foreach( get_post_types() as $type ) {
add_meta_box( $id, $title, $callback, $type, $context, $priority, $callback_args );
}
You can filter the specific post types you get back if you need more control by passing an array into `get_post_types()` with the post type criteria you want to match eg. `'public' => true`. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "custom post types, custom field"
} |
What is the official way to consume the Wordpress API? (api.wordpress.org)
Was wondering if anyone knows here if the API at api.wordpress.org is free to use without keys. I haven't really found any information about key registration.
I'd like to use it to make a few requests a day, really not many < 50 requests.
What's the official way to go about consuming that API?
Thanks! | So far as I know, it's available to use. Your site already hits it a few times each day for plugin updates, theme updates, etc.
It's not really well-documented, though ... so when you start building your code, **_please_** document what calls you're using and how you're using them in the Codex so everyone else can benefit. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 2,
"tags": "api, http api, plugin json api"
} |
How can I get automatically anchors for every h2-heading?
I usually type my posts directly via the HTML textarea, but I forget quite often to add anchors to the -Elements. Can they automatically be added with the text of the heading? How can this be achieved?
Does a plugin exist for this? | It is not exactly what I was looking for, but Table of Contents Plus also adds anchors to my headings. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "plugins, plugin recommendation"
} |
Feed links not working even with add_theme_support('automatic-feed-links')
My feed links don't work, even after I add this code to functions.php:
add_theme_support('automatic-feed-links');
When I try go to mysite.com/feed or mysite.com/?feed=rss or any of the links specified in the Codex, I don't get a feed with my content.
In Safari, I get this:
> Safari could not update this feed because the source file is no longer available.
In Chrome I get this:
<channel>
<title>My Site Name » Page not found</title>
<atom:link href=" rel="self" type="application/rss+xml"/>
etc.
My site used to have a feed through Feedburner, but I wanted to switch to built-in Wordpress feeds. It's very possible I'm misunderstanding something basic fact about how feeds work. What am I doing wrong? | The problem is that the front page is set to a static page. This became clear when I noticed that my feed problem was specific to the front page—feeds for taxonomy archives and post type archives work fine. Only the front page feed was causing trouble.
One way around this is to create a feed template. My starting point is the template here: <
Using a feed page template allows the same level of customization you can get from any template file—restrict your feed to certain post types, tags, formats, taxonomy terms, etc. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "rss, feed"
} |
How do I remove WordPress Custom Menus hover event and replace it with jQuery onclick?
I am using the WordPress (Appearance > Menus) feature to create a custom navigation menu. I created a menu item that has a dropdown and would like to activate the dropdown menu with a click rather than mouse hover. How would I go about doing this? I'm familiar wit jQuery, I just don't know how to remove the current hover state. | The hover is part of the theme you are using. You need to find whats causing the dropdown on hover and remove it. It'll either be javascript controlled or css. You can test if its javascript by disabling javascript, although is may have a css fallback. If its CSS use firebug to find the selectors for the nav menu. In your css file there will be something that looks like
ul li:hover ul{}
or if its a twentyten based them it'll be
#access ul li:hover > ul{}
You can comment or delete that line. Then use jquery add the css that :hover psuedo selecter was adding. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "jquery, menus, navigation"
} |
How To Remove The "+ Add New Category" Link From A Category Metabox
Inside of a Wordpress category metabox or any custom taxonomy box for that matter there is a link with the text "+ Add New Category" is there a way this link can be removed preferably without resorting to JS or CSS hacks to hide it? A way to hide it using some kind of filter or action hook would be best.
If no action hook or filter method exists to remove it, I would be open to JS and CSS solutions as a last resort.
The reason I am doing this is because I have a Wordpress installation integrated with Magento and I am creating and populating a custom taxonomy called "brands" with a list of brands from the Magento database so a post can be assigned to a brand. Obviously this means I don't want users to be able to add in their own terms and only be able to choose the brands added in dynamically to keep it in-sync with Magento.
Thank you. | The default metaboxes are registred in the file `wp-admin/includes/meta-boxes.php`. There you can find the function `post_categories_meta_box()` which will generate the taxonomy metabox. Currently there is no hook available to filter the output. But you can do one of the following:
1. Use `remove_meta_box()` to remove the existing category metabox and register your own with `add_meta_box()`. Copy&Past the existing code to your new metabox function and remove the code block from line `345` to `367`.
2. The cleaner way: Remove the `edit_terms` capability from your user roles with `remove_cap()`. If you look in the metabox function, on line `345` you can see an if-statement which checks if the user has the capability `edit_terms`. If so, the `+ Add New XY` will be displayed. Problem here, the name of the capability is dynamic and could be anything. If someone registers a taxonomy with a different capability naming, this will probably not work (untested). | stackexchange-wordpress | {
"answer_score": 14,
"question_score": 9,
"tags": "metabox, customization, magento"
} |
wordpress threaded comments - customize nested ul / how child ul is displayd
I just wasted 1 day trying to make wp threaded comments works... and I think I'm finally done!!!! except that it doesn't work properly - well it doesn't work the way I want ! :)
Child comments get displayed inside the comment li - I don't like this behavior, I'd prefer wp to display it right below the parent comment li.
So by default wp handles it like this:
<li id="commend-1">
comments parent here here
<ul id="child">
<li>child comment reply :P</li>
</ul>
</li>
Anyways, I want it displayed like this:
<li id="comment-1">
</li>
<li id="comment-2" class="isreply">
</li>
Is this possible without modifying core wp files? Did wp developers leave options that enable customization of how child/nested comments are displayed?
I'm including screen shot for better visual.
| What you need is a custom `Walker`. You will probably use `wp_list_comments()` somewhere in your `comments.php` template file. There you can pass a `walker` parameter in the argument array to tell WordPress you want to style the list on your own.
This requires you to extend the `Walker` class. The following resources should give you some examples.
1. Read the codex about the Walker_Class
2. Check the sourcecode of the base class in `wp-includes/class-wp-walker.php` or the extending `Walker_Comment` class in `wp-includes/comment-template.php` on line `1218`. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "comments"
} |
Redirection Plugin: Redirect all URLs with a regular expression
I understand little about regular expressions, but I need to figure one out to use with the Redirection plugin which supports redirects with regular expressions. <
What I need to do is redirect all urls in /oldsite/ to the domain root. That means any page in /oldsite/ like /oldsite/this-is-my-page.html, /oldsite/this-is-my-page-too.html, etc., needs to go to root via a regular expression.
I can't get a 301 redirect rule to work in .htaccess for some reason; there may be a restriction at the host, so I need to use this plugin.
It needs to be a regular expression in the format that the plugin understands. Some examples are in the docs for the plugin at that link above. The first field for a new redirection in the plugin takes the regular expression; the second field is the target URL.
This doesn't work:
Source: /oldsite/*
Target:
Nor does this:
Source: ^oldsite/(.*)
Target: | Got it to work with this:
Source: /oldsite/(.*)
Target: | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 5,
"tags": "plugins, redirect"
} |
How can I move/redirect single blog posts from one blog to another?
I see lots of answers about moving entire blogs, but here's my scenario:
I have a few blogs with a lot of content. I'm no longer publishing new content on these sites. I'm now publishing on another (new) site. I don't want to migrate all of the content from the previous sites, but I'd like to move a few "greatest hits" posts. What's the best way to migrate a few single posts from one site to another?
I'm thinking that for SEO purposes, it would make sense to have a redirect in place so that the posts currently receiving search traffic will pass that traffic onto the new site. | The best way of doing that is actually by just copying the post to your new blog, and on your old blog, add a rel="canonical" link to that page to your new post's URL. This will notify Google and other SE's that you want to have the other, new, page ranking, without actually having to annoy your users.
There are several plugins that can do canonical, two of them are mine, if you're not doing a lot of work on those old sites i'd recommend using my canonical plugin. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 3,
"tags": "redirect, seo, migration"
} |
trying to list users & display first - last name
For some reason this is not working for me :(
$get_members = array(
'blog_id' => $GLOBALS['blog_id'],
'role' => 'sm_flagar',
);
$blogusers = get_users($get_members);
foreach ($blogusers as $user) {
echo "<li><a href=\"".$user->user_url."\">". $user->first_name ." ". $user->last_name ."</a></li>";
} | `first_name` and `last_name` are stored in the `usermeta` table. Therefore you have to use `get_user_meta()` to return these data. Try this code snippet:
$users = get_users(array(
// blog_id is not required and will be set by WP_User
'role' => 'sm_flagar'
));
foreach ($users as $user) {
$firstName = get_user_meta($user->ID, 'first_name', true);
$lastName = get_user_meta($user->ID, 'last_name', true);
echo '<li><a href="' . $user->user_url . '">' . $firstName . ' ' . $lastName . '</a></li>' . PHP_EOL;
} | stackexchange-wordpress | {
"answer_score": 7,
"question_score": 1,
"tags": "users"
} |
how to modify request to get_template_part()?
i am modifying a P2 theme for a specific purpose, and it uses the `get_template_part( 'entry' )` function to get the the whole entry html.
What i then get is the who `<li>` element, but i want to be able to move things around [putting meta at the end of the post, for example]. but codex has no documentation for it [that i could find]. does this mean i have to use my own entry-getting method, or making a new loop? i hope not because P2 is so well sorted.
thanks a bunch for any tip!
adir | Just looked in the P2 theme files. The theme loads the `entry.php` with the function `p2_load_entry()` located in `inc/template-tags.php`.
If you want to edit the `entry.php` file and want to be on the safe side if P2 releases an update, you should create a Child Theme.
1. Create a new sub-folder inside `wp-content/themes/` e.g. `p2-child`
2. Inside the new folder, create a `style.css` with the content described in the above linked article. Be sure that you have added `Template: p2` to the comment block.
3. Copy `entry.php` to the new folder and edit it.
4. Go to WordPress Admin `Appearance > Themes` and activate your newly created P2 Child Theme. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "customization, get template part, theme p2"
} |
Loop.php vs looping inside template file
What is best practice for WP with regard to using loop.php (loop-single.php, etc) versus looping inside the template file? Does it matter with regard to efficiency or ? | Depends on whether you would use that single-loop in more places. If you're only using it in one place and that will remain the case, do it within single.php, if you're going to be reusing it elsewhere, I'd highly suggest using a single-loop template part. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 4,
"tags": "loop, customization"
} |
Add post thumbnail from external image with plugin
I'm currently writing a plugin modifying the post content with the wp_insert_post_data filter. While doing that I would also like to add a post thumbnail using an external image url. It doesn't really matter if the image is hotlinked or copied to my wordpress installation. Anyone knows how to go about that? | you should have a look to this blog post : <
then, if you can't use a remote image, just download it as a temporary file on your server, process and delete it.
One your image created, you should then insert it as an attachment ( and set it as the post thumbnail (
I hope it will help.
Cyril. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "plugins, plugin development, post thumbnails"
} |
Right click© images: protection
I saw there's a Wordpress plugin that prevents people from using right click on text or images, called WP Protect. I was wondering if there's a way to hardcode it into Wordpress instead of using a plugin.
What I'm worried about is mainly the images. Being able to mark text is perfectly fine with me.
I tried to find tutorials for this, but all I could find was the plugin I mentioned. | This functionality is Plugin territory. I strongly believe that the WordPress core team will _never_ consider such functionality for WordPress core.
Besides: such functionality is also pointless. Anyone who wants an image badly enough is going to be able to get them. (They can disable javascript thereby defeating the Plugin entirely; they can view source to find and load the imgae SRC URL directly; the browser probably has a copy of the image cached; RSS feeds have the images enclosed or linked; etc.) | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "images, copyright"
} |
Change admin bar to default:off
While I quite like the admin bar I actually want it to be OFF by default instead of ON ( I don't want to disable it altogether because I want users to be able to turn it on if they want - but but I don't want to have to manually turn it off for every user ) Is there a way to implement this. | add_action("user_register", "set_user_admin_bar_false_by_default", 10, 1);
function set_user_admin_bar_false_by_default($user_id) {
update_user_meta( $user_id, 'show_admin_bar_front', 'false' );
update_user_meta( $user_id, 'show_admin_bar_admin', 'false' );
}
Place in theme functions file or you can make into a plugin.
Once user registers it will go and set the users admin bar prefs to false. The user can then, once logged in, set this to true. | stackexchange-wordpress | {
"answer_score": 13,
"question_score": 6,
"tags": "theme development, functions, customization, admin, filters"
} |
How do I Import an Exisiting WP Project into Aptana 3?
How do I import an existing Wordpress project into Aptana 3.04.2?
I installed the Wordpress bundle in Aptana. I'm on a Mac running MAMP. My operating system is Leopard. My project is located at Sites->mysite.
1. I clicked "Import Project"
2. Clicked "General"
3. Selected "Existing Projects into Workspace"
4. Clicked "Next"
5. Select root directory-- browsed to mysite (But, I got "No projects are found to import".
How do I import my project (without messing it up)? Should I use "Create Project" instead? If so, how do I do that?
Thank you. | Ingo Muschenetz helped me out. This link provides the solution:
< | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "ide"
} |
Determine the category that an archive-page is for
On a _category archive page_ , how do I determine what category the archive page is for? I need either the _id_ or the _slug_ of the category.
I am _not_ looking for `get_the_category()`. This will give me all categories of the _posts_ on this page (which can be subcategories of the category that the page is for). Instead, I want the category that the archive page is for. _How can I get this category?_ | the ID of the current category will be available in the `cat` query var:
get_query_var('cat'); | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "categories, archives"
} |
Editing Theme and Moving Servers
Ok, So I have a wordpress installed on a test server. I just edited the default theme to get my desired result. My question is could I just install a new version of wordpress on another server and copy/paste my theme - simple as that? | If you haven't added a bunch of content and widgets on the local server, yes, it can be as easy as that.
If you want to move _everything_ \- all your settings and content and such - you can follow these instructions: <
G'luck! | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "themes, import, server, export"
} |
How to sort posts based on the value (number) of a post's metadata?
I'm using the GD Star Rating plugin and the bbPress plugin. The first plugin do have a argument to sort posts by number of votes. But unfortunately, It doesn't work with `WP_Query` (and apparently the **bbPress loop** uses it).
That's why I wanted to create my own way of sorting custom post types in a custom loop.
Let's say I have a function or a variable that outputs the number of votes of each post:
<?php votes_number(); ?> or $votes_number
How can I use them in something like this:
query_posts( "orderby=votes_number" );
or
query_posts( "my_custom_orderby=votes_number" ); | To order using post based custom fields you have to store your variable in an actual field using `add_post_meta` or `update_post_meta`, or manually add it to the post field.
That way you can use `WP Query` to query the meta value for that field and order by the value. For example;
//adds a value to a field with the key name 'vote_field' and your variable.
<?php add_post_meta($post_id, 'vote_field', $votes_number); ?>
//query the key 'vote_field' and order by
$query = new WP_Query( array (
'post_type' => 'post',
'meta_key' => 'vote_field',
'orderby' => 'meta_value',
'order' => 'ASC' ) );
Also there are additonal paramters you can use such as `meta_value_num` and 'meta_compare' | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "php, loop, sort"
} |
How can I edit the slugs of tags?
I'm interested in specifying different URL slugs for tags than the text they contain (e.g. changing the slug for a "QnA" tag to "questions-and-answers"). What's the easiest way of making and maintaining these changes for a large number of tags? | **Dashboard -> Posts -> Post Tags**
Click Tag (or click "Edit" in the hover quick-menu) to edit the tag's details, including slug. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "tags, slug"
} |
How do I query based on the modified date?
I would like to list posts by the "modified" date not the published date. Is there a way to do this?
$documents = array('posts_per_page' => 10, 'post_type' => 'documents',);
query_posts( $documents );
get_template_part( 'loop', 'docid' );
wp_reset_query(); | <
'orderby' => 'modified' | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "query posts, loop, customization, date"
} |
debugging register_activation_hook()
I'm curious if there is a known issue with WordPress or PHP where the environment may degrade to a point where WordPress simply ignores calls to register_activation_hook(). I was pulling my hair out for an hour on my local environment running MAMP when I had a coworker test the code on her machine; exact same code works on one machine but not the other.
In this case I simply wanted to append messages to the log file which I'm tailing in real-time.
error_log("Plugin code is being processed");
register_activation_hook( __FILE__, 'myplugin_activate' );
function myplugin_activate()
{
error_log("Attempting to activate");
die("Should not activate");
}
The output on my machine running MAMP and clicking on the "Activate" link under my plugin:
[22-Sep-2011 22:37:16] Plugin code is being processed
[22-Sep-2011 22:37:16] Plugin code is being processed | After a little more thought, I think using a resolved path lookup might be safer:
function plugin_symlink_path( $file )
{
// If the file is already in the plugin directory we can save processing time.
if ( preg_match( '/'.preg_quote( WP_PLUGIN_DIR, '/' ).'/i', $file ) ) return $file;
// Examine each segment of the path in reverse
foreach ( array_reverse( explode( '/', $file ) ) as $segment )
{
// Rebuild the path starting from the WordPress plugin directory
// until both resolved paths match.
$path = rtrim($segment .'/'. $path, '/');
if ( __FILE__ == realpath( WP_PLUGIN_DIR . '/' . $path ) )
{
return WP_PLUGIN_DIR . '/' . $path;
}
}
// If all else fails, return the original path.
return $file;
} | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 2,
"tags": "plugins"
} |
Plugin or method to delete uploads not in media library?
Over time working on a local and development server I've accumulated some junk in my `wp-content/uploads folder` which are not in the database. The folder and database entry are fairly large and so I was wondering if there was a plugin or way to do some type of "garbage collection" and delete items in the uploads folder which are not in the media library. | There is no easy way to do this. You could query the WP database for wp_posts that are media uploads and then run a script to match those again the files in the uploads folder, but even this would be a little shaky. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "plugins, uploads, media"
} |
change sidebar or just widgets for 2 specific post type single posts
I would like to show a different sidebar for 2 specific posts(same custom post type). I understand how to do this using separate templates for different pages, but I want to have it all happen in the single-posttype.php page. Or am I thinking about this wrong? My end goal is to show different text widgets in the sidebar on specific posts. | I think Widget Logic is what you're looking for. It adds a field to each widget to allow you to specify which post get which widgets. It uses the standard Conditional Tags making it easy to use. You'd just want to do something like
is_single( 'Slug1-or-ID1' ) || is_single( 'Slug2-or-ID2' )
You could also try the a post type method to show only a specific post type:
//not tested but something like
global $post; return ('book' == get_post_type($post)); | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "sidebar"
} |
No "available widgets" (wordpress 3.2.1 multisite)
I have no widgets available any ideas?
I've tried the "Twenty Eleven" Standard Theme and the custom one (Lotus).
No widgets are listed, I am looking for the custom_menu widget.
In my other wordpress installation I have plenty of widgets available.
**Update** : I use a multisite installation and I found that the blog_id in wp_options is set to 0 (not sure this has something to do with it?) | Stupid mistake, I commented this out by mistake in wp-includes/widgets.php line 323:
function register($widget_class) {
// $this->widgets[$widget_class] = & new $widget_class();
} | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "themes, widgets"
} |
.current_page_ancestor broken in Twenty Eleven
I would like to have a level 1 menu in a vertical menu and a full menu in a vertical menu in the left sidebar in Twenty Eleven. My problem is that I would like to make the top item bold if the user is in it, or in one of it's child menues.
The ideal solution would be to apply a rule for `.current_page_ancestor`. But for my biggest surprise, that rule IS already in the original css file for Twenty Eleven. But it seems to be broken, as nothing happens!
#access .current_page_item > a,
#access .current_page_ancestor > a {
font-weight: bold;
}
Do you know how to fix this? Is there a ticket for this bug already?
To have an idea, have a look at this site, I made the selector red to make it visible. What I would like to achieve is that the top menu stays red even if I'm in one of the child menus on the left.
sample page | Try adding the `.current-page-ancestor` selector to your style, note the use of hyphens instead of underscores. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "theme development, menus, css, theme twenty eleven"
} |
How do you force the wordpress dashboard to be 1 coulmn by default?
How do you force the wordpress dashboard to be 1 coulmn by default? I want to show the dashboard as a single column for all users. | I found a promising looking answer to this question in the following post: <
It recommends using this code in the functions.php file:
function so_screen_layout_columns( $columns ) {
$columns['dashboard'] = 1;
return $columns;
}
add_filter( 'screen_layout_columns', 'so_screen_layout_columns' );
function so_screen_layout_dashboard() {
return 1;
}
add_filter( 'get_user_option_screen_layout_dashboard', 'so_screen_layout_dashboard' );
Hope that helps! | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 0,
"tags": "wp admin, dashboard"
} |
Automatically delete default posts and pages on theme install?
Is there a way to automatically delete the default wordpress posts and pages when activating theme theme? | The following question gives you some insights how you can create an initialization script which should cleanup a fresh WordPress installation. It's not complete but it's a good startpoint.
-> Initialization Script for “Standard” Aspects of a WordPress Website? | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "posts, themes, pages, activation, customization"
} |
Having trouble with the_post_thumbnail to display thumbnail with custom size
I have code that looks like this:
$post_thumbnail = the_post_thumbnail( array ( $w, $h ) );
I want to know what I'm doing wrong. When I pass in values for width and height, Wordpress returns an image with the correct hight but with the incorrect width. Is it possible for me to get the exact image specified? | Always start with the Codex. According to the function reference for `the_post_thumbnail()`:
> Parameters
>
> $size
>
> (string/array) (Optional) Image size. Either a string keyword (thumbnail, medium, large, full), or any custom size keyword defined by add_image_size(), or a 2-item array representing width and height in pixels, e.g. array(32,32).
>
> Default: 'post-thumbnail', which theme sets using set_post_thumbnail_size.
>
> **PLEASE NOTE: The crop does not work in Wp 3.0+.** All that is needed for WP 3.0+ is the call for the thumbnail to post. Then proceed to media in the dashboard and set your thumbnail to crop to the size you wish to use.
You need to create your custom image size, via `add_image_size( $name, $w, $h, $crop )`, and then call `the_post_thumbnail( $name )`. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "posts"
} |
Best Shopping Cart for WordPress
What is the most complete WordPress shopping cart at the moment?
GetShopped / Cart66 / Tribulant Shopping Cart ?
Or something else? | For anyone who comes across this, after some research I'm going with Cart 66 which seems to be the hottest e-commerce plugin for wordpress sat the moment. | stackexchange-wordpress | {
"answer_score": -1,
"question_score": 0,
"tags": "plugin recommendation, e commerce"
} |
Category and tag with same name
IN my blog, if I have a category and tag with the same name, it will make the tag have a number in the URI.
Example:
**category/php**
**tags/php-2**
Is there anyway to make my tags with the same name as an existing category, to not append a number to the end of them for my links? | Tags and Categories use the same system, So that is not possible. It will not hurt SEO in any way to use php-2, it is just visually displeasing. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 3,
"tags": "categories, url rewriting, tags"
} |
wordpress featured image
I'm new to Wordpress and I'm trying to create a new theme for it. I've downloaded the latest version (3.2.1) and installed it successfuly. But when I install my wordpress theme (to start to add the PHP) and try to create a new post, what happens is that the Set Featured Image box disappears and it only shows again when I return to the default theme.
Any suggestions for this? Thank you | The most simple form of the featured images (post thumbnails) looks like this:
You need to have this piece of code in your functions.php file:
add_theme_support( 'post-thumbnails' );
Then in the index.php, or any other template file you want to show the post thumb or featured images, you would add this:
<?php the_post_thumbnail( 'thumbnail' ); ?>
The code above usually goes just after <`?php the_title(); ?>`
Once you've added those, you should see them on posts. To have them on posts and pages, use this in place of the first code for the functions.php file:
add_theme_support( 'post-thumbnails', array( 'post', 'page' ) ); | stackexchange-wordpress | {
"answer_score": 0,
"question_score": -1,
"tags": "post thumbnails, images"
} |
wordpress featured image
I'm new to Wordpress and I'm trying to create a new theme for it. I've downloaded the latest version (3.2.1) and installed it successfuly. But when I install my wordpress theme (to start to add the PHP) and try to create a new post, what happens is that the Set Featured Image box disappears and it only shows again when I return to the default theme.
Any suggestions for this? Thank you | What is happening is that your theme does not have support for featured image. What you need to do is add in the functions.php file of your theme the line :
if (function_exists('add_theme_support')) {
add_theme_support( 'post-thumbnails' );
}
and then you will be able to use featured image in your theme | stackexchange-wordpress | {
"answer_score": 3,
"question_score": -1,
"tags": "php"
} |
Permalinks on post is working, on pages 404 error
I am having troublle with setting my permalink in wordpress site.
I changed the permalink from default to custome : `%postname%`. In this case my posts are working perfectly, but the pages are not. They generates a error 404 page not found.
I've changed the .htaccess file permission, did everything, but nothing is working.
Any suggestion to solve this? | I figured it out! It was basically a mysql user privilege problem. For security reasons, I had switched off a lot of permissions, so it couldn't write the data. I gave the conflicting permissions and it worked! Thanks to Jeremy for his help! | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "permalinks, 404 error"
} |
wp-admin blocking causing http error on uploads
I'm using this function to prevent users apart from admin from getting to the backend of wordpress. (Note, that addition to allow ajax requests too):
add_action( 'init', 'my_block_users' );
function my_block_users() {
$isAjax = (defined('DOING_AJAX') && true === DOING_AJAX) ? true : false;
if(!$isAjax) {
if ( is_admin() && ! current_user_can( 'administrator' ) ) {
wp_redirect( home_url() );
exit;
}
}
}
Trouble is, it causes an http error when uploading images etc. Does anyone know a work around for this? Thanks! | Works on my side. Try disabling your plugins and test again.
Btw. You could use `admin_init` instead of the `init` action hook. This way, the snippet will only be executed on admin requests. This way, you can remove the `is_admin()` check in the function. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "wp admin"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.