INSTRUCTION
stringlengths 11
999
| RESPONSE
stringlengths 0
999
| SOURCE
stringlengths 16
38
| METADATA
dict |
---|---|---|---|
Enqueuing a script before anything else
I wondered if it was possible to change the order in which a script is enqueued.
I ask this because I wish to include the HTML5 enabling script but it needs to be included before any styles.
Is there any way to change the order?
I could obviously hard code it into the themes header, but I would prefer to enqueue it.
Thanks for any suggestions you may have. | You can change the order of the scripts but can't have one script load before anything else. The HTML 5 enabling script is IE conditional so you probably don't want to use `wp_enqueue_script` as it would load for all browser users which isn't necessary.
It's ok to hard code it in your themes header. Even Twentyeleven does it this way.
Also there is nothing that says it has to be added before any styes. It just has to be before the opening `<body>` tag. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 0,
"tags": "wp enqueue script, css, scripts, wp enqueue style"
} |
Getting started with e-commerce sites on WordPress
Are there any good resources for building an e-commerce storefront? I am aware of the e-commerce plugins available but I am mainly interested in learning practices and techniques for the design and development of an e-commerce site for someone who has never built one before.
Obviously, nothing is stopping me from just trying, but figured I would ask if there are good resources out there to learn from. | Larry Ullman's book PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide has an excellent chapter on building an e-Commerce website. It has nothing to do with WordPress, but I found it to be an excellent introduction to the very basic e-Commerce concepts way back when I read it. I think it would be a great place to start. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "e commerce"
} |
Add Caret to Menu Items with Sub-Menus in WordPress Theme
I'm working on a custom theme using wp_nav_menu(). What I want to do is add a caret to menu items that have sub-menus. For example, If my menu looks like this:
* Menu Item 1
* Menu Item 2
* Menu Item 2a
* Menu Item 2b
* Menu Item 3
I want to be able to format it like this:
* List item
* Menu Item 1
* Menu Item 2 >
* Menu Item 2a
* Menu Item 2b
* Menu Item 3
Without knowing the structure of the menu. This seems like a pretty common formatting problem, so I was wondering if there is any built-in functionality to provide for this. | I do this using jQuery (since it doesn't necessarily need to be in the TEXT (for screen readers, etc.) - just another option...:
jQuery(document).ready(function() {
jQuery('ul#nav li').has('ul').addClass('parentul');
});
Then for that "parentul" class I put in a background image of an arrow and position it to the right > ... | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 7,
"tags": "theme development, menus, walker"
} |
List taxonomy terms for post as checkboxes
I'm modifying the plugin `Wordpress Frontend User` for my custom post type(s). What I need to edit is the custom taxonomy terms. In order to do this, I need to list my terms as labels and have checkboxes associated with the labels (in the end associated with the taxonomy when I send a post update).
What I have now is as follows:
$jobsTerms = get_terms('jobtype',array( 'taxonomy' => 'jobtype' ));
foreach($jobsTerms as $term){
echo "<label for='term-" . $term->slug . "'>" . $term->name . "</label>";
echo "<input type='checkbox' name='term" . $term->slug . "' value='" . $term->name . "' />
}
But other than that, I'm lost as to how to check to see if that post has a term selected (if so add `checked=checked` to the input).
I'm also lost as to how to update this taxonomy when I click submit (which fires a couple custom `update_post_meta` calls and a `wp_update_post` call.
Any help? | Try this:
$jobsTerms = get_terms('jobtype',array( 'taxonomy' => 'jobtype' ));
foreach($jobsTerms as $term){
$checked = (has_term($term->slug, 'jobtype', $post->ID)) ? 'checked="checked"' : '';
echo "<label for='term-" . $term->slug . "'>" . $term->name . "</label>";
echo "<input type='checkbox' name='term" . $term->slug . "' value='" . $term->name . "' $checked />";
}
Replace $post_id with whatever you need to get the ID, I'm not sure where exactly this code goes. It may be $post->ID. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "plugins, custom post types, custom taxonomy, terms, wp update post"
} |
Different thumbnail sizes
Is it possible to set a different thumbnail size for different pages? For example, I want the thumbnails on my category, archive and tag view to be bigger than on my home.php.
Right now I have the following code in my function.php:
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 250, 165, true );
Do I have to modify my function.php or is it also possible to modify the thumbnail size in the home.php where I want the size to be different from index.php? | In your functions file you need to add image sizes:
< | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "post thumbnails"
} |
Can I attach a document (eg: PDF) but have a JPEG as a thumbnail?
Is there a built-in feature or plugin that allows you to attach a document to a post or page such that the actual attachment file is one thing (eg a PDF) but the thumbnail images are another (eg a JPEG)? CLARIFICATION: the thumbnail does not need to be automatically generated (it could be a separate upload)
The use case here is a document library, where you have a little screenshot of what that document looks like but when you click the attachment, you can download the original document. | WP-Filebase ended up being the free plugin solution we went with. This is actually a pretty cool plugin with a lot of power under the hood, though the interface is far from slick. When you upload any kind of document, you have the option to go to an "Advanced" upload form, which allows you to upload a separate thumbnail for the document. Then, when you decide to list the document, whether using shortcode, or automatically linking the doc to a page, you'll see the thumbnail instead. Unfortunately, no ability to generate / manipulate / scale the thumbnail unlike the native Media upload process. Still, it's a useful tool with some basic Document Management features that make it a good fit for small DMS requirements. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 3,
"tags": "attachments, uploads, thumbnails"
} |
Wordpress file browser
I see plugins that somehow hook into the Wordpress file browser (so that users can either upload an image to the image library or choose an image from the image library) but I've been searching through the codex and can't seem to find a simple way to do this.
I'd like to add the image browser/file upload to my options page... | Read this article: Using the WordPress Uploader in Your Plugin or Theme. I've successfully used this method to integrate the WP uploader with my own plugin. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "images"
} |
Load images after page load
I just heard somewhere that by using some javascript it is possible to load of a page after the entire page load completes,
When I googled, I found LazyLoad, but it seems that latest browsers are not supporting it.
My site has some images because of which sites becomes slow, is it possible to load images after the completion of page load? | I took a look at it on Github: < \- it appears that there was some sort of fix that was merged in that helps, though I'm not sure if it really fixes the issue. It appears to work for me as expected in FF6, though my connection is probably not slow enough to really notice much of a difference.
There's a WP plugin for Lazy Load that looks like it's working just fine for people and has been updated fairly recently: < I'd say it doesn't hurt to try it out and see if that works. Who knows, perhaps the developer just hasn't updated the warning in a while! | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "javascript"
} |
Pagination problem with multiple loops on the same page
I'm using 4 custom loops to display 3 posts on each one and every loop has its own pagination which works fine once the page loads up, the problem is that when I click on the 2nd page of the first loop it does show me the next 3 posts of that loop but it does the same for the other 3 loops, so if one of these loops has only 2 posts it won't show any if I click on the 2nd page of any of the other.
Is there a way to page the pagination aware of what the loop is and only scroll through that loop?
Thanks in advance! | you might wanna try wp_reset_query(); at the end of your loops | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "wp query, pagination, loop, customization"
} |
__FILE__ in WordPress plugins
I'm using Sidebar Generator in all my themes.
The plugin works perfectly normal from "plugins" directory, but I want to embed it somehow to my themes, so it won't display on Installed Plugins list.
I've just copied sidebar_generator.php (the whole code is luckily in one file) to mytheme/plugins and included it in functions.php
require_once (MY_PLUGINS . '/sidebar_generator.php');
Now, it worked for all other plugins, but not for this one! This way when I click on "Sidebars" it refreshes the actual page instead of loading plugin's admin_page.
Any ideas why is it happening and how to make it working?
I believe the problem lays here:
add_submenu_page('themes.php', 'Sidebars', 'Sidebars', 'manage_options', __FILE__, array('sidebar_generator','admin_page'));
Chaning **FILE** to something else helps, but I'm not sure how to point this submenu link at the actual plugins admin page. | It should work (and does when I test on a new WP install) with `__FILE__`, though it's not recommended because it exposes the server path and is just generally an ugly URL. You can replace it with a unique identifier like 'sb-generator-options' or whatever really, as long as it's unique. the important part is the last param that tells it what function to use to render the page.
Are you maybe moving `add_submenu_page` out of the plugin file, or are you just editing it in place? | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "plugins"
} |
How can I remove filters from custom post types?
I created a custom post type which I'll use as landing page for PPC. Now on that custom post type I would like to remove all the filters which are adding the social media buttons for example. I tried already with the following code but that did also remove the shortcode filter which I would like to keep on that custom post type. Here's the code I used:
function landingpage_remove_plugin_filters() {
global $wp_filter;
global $wp;
if ($wp->query_vars["post_type"] == 'landingpage') {
remove_all_filters('the_content', 'plugin_filters');
}
}
add_action('wp','landingpage_remove_plugin_filters');
Does anyone know what I need to change in order to keep the shortcode filters on that custom post type?
Thanks a lot for your efforts.
Daniel | Try re-adding the 'do_shortcode' filter like so:
function landingpage_remove_plugin_filters() {
global $wp_filter;
global $wp;
if ($wp->query_vars["post_type"] == 'landingpage') {
remove_all_filters('the_content', 'plugin_filters');
add_filter('the_content', 'do_shortcode');
}
}
add_action('wp','landingpage_remove_plugin_filters'); | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "custom post types, the content, filters"
} |
Multiple permalinks
My blog uses the `/?p=378` permalink structure for some years. This isn't very helpful with Google Analytics, and I would like to change it to the `YEAR/MONTH/DAY/post-title` structure.
Is there a way to do this without losing backward compatability, so that old link will work? | The old link (?p=378) will always work, and it will redirect to the "pretty" permalink. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "permalinks"
} |
Show all posts in category
I am trying to show all posts in each category. I've been searching around and it seems I need to have either the category `slug` or `term_id` to do so, like the code below.
<?php query_posts('category_name=MyCategory&showposts=9999'); ?>
I'm currently editing the `archive.php` how to get the `slug` name?
Thanks. | to get the category slug of the category archive:
$cat_slug = get_category(get_query_var('cat'))->slug;
alternatively, to get the category ID of the category archive:
$cat_id = get_query_var('cat'); | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "posts, categories, loop, archives, slug"
} |
how wordpress generates permalinks as /%category%/%post%/
I am not here to discuss the efficiency of using categories as the base for permalinks.
I would like to know in **what file and what line is the code to how Wordpress picks out a category for the permalink if the post is in multiple categories**. I asked this on IRC a while ago and I can't find the code anymore.
Thanks. | `get_permalink` in `/wp-includes/link-template.php`, line 80 | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "categories, permalinks"
} |
Auto post Spams on my wordpress blog?
i don't know what the hell are these spam links on my friend's photo-blog posts! when i publish a post, this texts shown there! what should i do? (sorry for my very bad English) blog: <
| You have malware, either by downloading a free theme with malware in it or someone exploited your site.
Verifying that I have fully removed a WordPress hack?
< | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "posts, spam"
} |
How to assign a post to a post parrent?
I want to be able to add posts to a post parent in wordpress. Is there a way? There is such option for pages but I need it for posts to. Any ideeas?
Ty! | Posts & Pages are "built in" Custom Post Types. So something that was delivered as a pre-configuration when WP was installed. There's also other built in stuff like Tags & Categories which are basically nothing other than custom taxonomies.
And you're lucky: You can simply use the API and add your own, hierarchical custom "post" type.
register_post_type( 'hierarchical' => true ); | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "posts, query posts"
} |
query_post order desc
According to:
To show all posts in a category:
query_posts( array ( 'category_name' => 'The Category Name', 'posts_per_page' => -1 ) );
Works great, but if I want to show the posts
> ORDER BY ID DESC
Anyone have any idea how to do that? | You need to use this to parameters `orderby` and `order`
<?php query_posts( array( 'category_name' => 'my_category_slug', 'orderby' => 'ID', 'order' => 'DESC', 'posts_per_page' => -1 ) ); ?> | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 0,
"tags": "categories, query posts, posts"
} |
Show current page featured image in sidebar
How do I call the current post's featured image in the sidebar? and if there is none, then a backup image? | I'm assuming you're going to be outputting this on a singular page (Post, Page, Attachment)?
If so, the easiest thing to do is to put your post AND sidebar content _inside_ the Loop, so that you have access to the `$post` global, and post-related template tags.
Alternately, you could define a variable, _inside_ the Loop, to hold `$post-ID` so that you can reference it _outside_ of the Loop, i.e. in your sidebar.
In either case, _inside_ the Loop, you would have e.g.:
$post_id = get_the_ID();
Then, in your sidebar:
if ( has_post_thumbnail( $post_id ) ) {
the_post_thumbnail( 'sidebar_post_thumbnail' );
} else {
// code to output your default image
}
Note: I'm assuming you'll create a custom image size to output in the sidebar, e.g.
add_image_size( 'sidebar_post_thumbnail', 150, 9999, false );
(which goes in `functions.php`, of course) | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 2,
"tags": "post thumbnails"
} |
One comment per user per post
How can i disable the comment form, if the user is already submitted a comment for the specified post?
I am using this now, but this is only good for 1 post / user / website.
<?php
global $current_user;
$args = array('user_id' => $current_user->ID);
$usercomment = get_comments($args);
if(count($usercomment) >= 1){
echo 'disabled';
} else {
comment_form();
}
?> | Simply add the post_id parameter to the `get_comments` arguments array something like:
global $current_user,$post;
$args = array('user_id' => $current_user->ID,'post_id' => $post->ID);
$usercomment = get_comments($args);
if(count($usercomment) >= 1){
echo 'disabled';
} else {
comment_form();
} | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 2,
"tags": "forms, comments"
} |
Is there a plugin or simple way to add a multiple images metabox to a post?
I am looking for a way to create a custom field/metabox that allow to attach **multiple** and **infinite** images to a post. This would allow to create a custom post type for a portfolio and allow to attach images **without pasting them inside the post textarea**.
Most plugins I've seen allow for only 1 image. I've got the inspiration from the awesome ProcessWire CMS, that allows for this functionality right out of the box. It would be awesome to have this in Wordpress too!
Is there a plugin I'm missing? Could this be done? | This cab be done very easy by custom code or using `Meta Box Script For WordPress` which makes my life a lot easier when it comes to creating custom meta boxes. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "images, uploads, cms"
} |
How to create a second index.php?
I need a duplicate of `index.php`, but slightly modified. I added a "vote it up" plugin. So, I want the user to select how to display posts - by new or by popular. I know what to add to second `index.php`, but how to create a second `index.php`, thats the problem. | Elaborating on Rachel Baker's answer:
Copy the index.php file and name it something like popular.php. At the very top, paste the following:
<?php
/*
Template Name: Posts by Popular
*/
?>
Now, go in to the WordPress admin and create a new page, called something like "By Popular". On the right-hand side, select the "Posts by Popular" template where it says "Template" (screenshot). Publish the page, and when you view it you should see your new page.
Create a link to this page in the nav menu or wherever, and then your users will be able to access the new page. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "themes, child theme"
} |
Script that gets the first tag of post and query all other posts with the same tag
The script gets the first tag of a post and retrieves in a wordpress loop all other posts with the same tag. I can't seem to get it working:( Any ideeas?
$posttags = get_the_tags();
$count=0;
if ($posttags) {
foreach($posttags as $tag) {
$count++;
if (1 == $count) {
$tag = $tag->name . ' ';
}
}
}
query_posts('tag='.$tag.''&'showposts=-1');
while (have_posts()) : the_post(); ?>
<p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
<? endwhile;
wp_reset_query();
Take care | the query expects the tag slug, not the tag name:
$tag = $tag->slug . ' ';
and there is an error in the query syntax; corrected:
query_posts('tag='.$tag.'&posts_per_page=-1');
edit: full code rearranged:
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
$tag = $tag->slug; break;
}
query_posts('tag='.$tag.'&posts_per_page=-1');
while (have_posts()) : the_post(); ?>
<p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
<?php endwhile;
wp_reset_query();
} | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "query posts, tags, loop"
} |
get_term_by not working when in functions.php
I have an odd issue with get_term_by(). It's working fine when I use it inside a template, but when I use it in functions.php it just returns false.
$term = get_term_by('slug', 'some-term', 'some-taxonomy');
var_dump($term);
Any explanation as to why this is happening would be greatly appreciated. | This is probably happening because the taxonomy you're trying to query is registered yet. Eg. The WordPress environment is loaded when a theme's functions.php file loads, but many plugins/themes/core functions don't register taxonomies until later.
Try hooking into `init` with a really high priority number and running the `get_term_by` function. Like so:
<?php
add_action( 'init', 'wpse27111_tester', 999 );
function wpse27111_tester()
{
$term = get_term_by('slug', 'some-term', 'some-taxonomy');
var_dump($term);
} | stackexchange-wordpress | {
"answer_score": 10,
"question_score": 6,
"tags": "custom taxonomy, functions, terms"
} |
How do I create pages within a Wordpress post?
I run a music blog and I want to do a countdown of our top 50 tracks of 2011 so far.
There's no way that I want to add 50+ images and Audio Players into just one post, and I don't want to break the post down into separate posts either.
Is there some kind of plugin or function that will allow me to add pages to the post so I could have say 10 tracks per page? | WordPress actually comes with pagination built in. I don't believe there's a button on the visual editor by default, but in HTML mode you should be able to insert `<!--nextpage-->` wherever you'd like a page break and it will work. Styling the pagination links would likely be the next step after that: < | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "plugins, functions, pages"
} |
Query all posts which do not have tags assigned to them
Is there a way to query posts which **do not** have tags assigned to them?
query_posts('tag='tag_exmaple'&posts_per_page=-1');
Ty very much! | Either use the `tag_not_in` parameter if you have the tag id and if not then you can use `tax_query` parameter like so:
$tag_to_exclude = 'example_tag';
$args = array(
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'post_tag',
'field' => 'slug',
'terms' => array($tag_to_exclude),
'operator' => 'NOT IN',
)
);
query_posts($args); | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "tags, query"
} |
Simple text and image slider
I've been looking for a slider that can slide whatever kind of content that I want to enter. I tried out various Wordpress plugins, but most of them only can slide Wordpress posts or images only with a small caption. I'm looking for something like the WP Photo Slider 50. Unfortunately this slider doesn't work in my theme, though as there is a jquery conflict and I have no clue how to modify the plugin so that there won't be a conflict (if possible at all).
I was wondering if somebody could help me find a slider plugin similar to the one above, direct me to a "how to creat a slider yourself" website or help me figure out how to get rid of the jquery conflict with the plugin mentioned above.
My website (still heavily under construction): here
Thanks a lot in advance :) | I use jQuery Scrollable for all my slider needs. It supports sliding of any type of content, and content can slide horizontally and vertically.
JQuery Tools and JQuery Scrollable are free, open sourced, and well documented. The support forums can be very useful if you are having problems implementing scrollable. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "jquery"
} |
how to check if front page is set to show a static page
I need to determine whether the reading settings are set to use a static page or the latest post for the front page.
Is there a conditional that will return true if the front page is set to show a static page? I don't need to check what page the static page might be, just if its a static page at all.
For this scenario would it be correct to use:
if( is_front_page() && !is_home() ){
// seems we're on the front but not on the blog home,
// so it must be a static page..
} | Your conditional logic makes sense as well but you're probably looking for this:
if ( 'page' == get_option('show_on_front') ) {
// do something
}
Hint: You can append `options.php` to the WordpPress admin url like this:
` to see all options.
_( that's where I found the answer for you .)_ | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 5,
"tags": "conditional tags"
} |
How to output message during plugin activation
I am developing a plugin, but during the activation phrase I am constantly facing bugs. However there is no easy way to display error messages, since echoing stuff would result in 'unexpacted output' error. I tried the admin_message hook but it doesn't work. How can I alert the user if some stage of the activation has failed with reason? | For testing purposes you can use the log system (php_error.log):
error_log('Plugin activated', 0);
// Check for DB table existance
if(!$this->hasDBTable()){
error_log('Database not present', 0);
if($this->createCELabelsDBTables()){
error_log('Database was created.', 0);
} else {
error_log('Error creating the CE Labels Plugin db tables!', 0);
}
} else {
error_log('Database OK', 0);
}
To output error to the user without the "Headers already sent" error, you can use the php function trigger_error:
trigger_error('PLUGIN OK',E_USER_ERROR);
With Wordpress must always be E_USER_ERROR or it won't display the message.
I know the error_log works perfectly since I'm using it, but the trigger_error displays to must information. Try it and see for your self :) | stackexchange-wordpress | {
"answer_score": 9,
"question_score": 11,
"tags": "plugin development, activation"
} |
add action for displaying posts using a shortcode
I'm developing a simple plugin for letting a user insert a post from the frontend.
I have a shortcode [add-post] which a user can put on any page, say, for eg. My Wall Page
Now on My Wall Page a simple form comes up which has a title field, a content field and a category select field so that user can choose which category to put his post into.
I'm not sure as what the action should be?
add_shortcode('add-post','my_fucntion');
function my_function(){
<form>...My form for inserting a new post goes here...</form>
}
add_action('????', 'my_fucntion');
What should the hook be? I tried 'init', 'widgets_init' but to no avail. If i don't add any action or even if I do add 'init' or 'widgets_init', it displays my form 3 times; two times at the top and one time in place of the shortcode (i.e, it replaces my shortcode) | You don't need to hook into an action for a shortcode - adding the shortcode using `add_shortcode()` will make it run when you call `the_content()`. That said, your function for your shortcode needs to **return** your output, not just echo it outright. Otherwise you will find that your form will appear much earlier than you expect it to. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "plugins, plugin development, hooks, actions"
} |
Editing wordpress dashboard
I've almost edited dashboard of wordpress but now i'm confused with sidebar I can't find page where appereance, posts, comments, settings etc etc. Can anyone know where i can find codes of that sidebar | What exactly do you mean by editing? I hope not modifying WP core files, which is considered bad practice and incompatible with updates?
Administration menus are considered to be some of the most nasty parts of code in WP and are hard to deal with. For some top level overview see Administration Menus in Codex, but for really deep customization there are no easy ways or guides (that I know of). | stackexchange-wordpress | {
"answer_score": 0,
"question_score": -1,
"tags": "dashboard"
} |
Apply Classes to post text inside editor
I am using a theme that comes with several different font stylings for headers and text. However there is no simple way to apply these classes inside the editor. How can I enable a drop down similar to TinyMCE that allows me to select text and apply a class/style to it in order to have my marketing and sales department style their posts. | You'll need two code snippets. The first puts the select menu there. The second populates it.
This is based on this tutorial, but slimmed down a bit.
add_filter( 'mce_buttons_2', 'mrw_mce_bad_buttons' );
add_filter( 'tiny_mce_before_init', 'mrw_mce_init' );
function my_mce_buttons() {
return array('formatselect', 'styleselect', '|', 'forecolor', 'underline', 'justifyfull', '|', 'pastetext', 'pasteword', 'removeformat', '|', 'charmap', '|', 'outdent', 'indent', '|', 'undo', 'redo', 'wp_help' );
}
function my_mce_init( $args ) {
$args['theme_advanced_styles'] = 'Display Name=class-name,Display Name=class-name,etc.';
return $args;
}
The "Display Name" and "class-name" above are up to you, but that's what determines what classes get listed. I also usually use this as an opportunity to kill off the 3rd, 4th, and 5th options in the second row of buttons, but I put them back in for this snippet. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "css, editor"
} |
Which plugin gives me pretty html syntax in the editor/dashboard?
I'm looking for a plugin that gives me some on-the-fly syntax highlighting in the HTML editor of posts and pages. I swear I've seen it somewhere, but I can't find it, all the ones I find are for showing it nicely on the front-end of the post/page to users.
In case it's not clear, I Would like to have my HTML editor tab show me stuff like this: | Try < | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "plugin recommendation, syntax highlighting"
} |
Custom Post Type and Taxonomy Rewrite Error
The following code is adapted from Jan Fabry's answer. Mixing custom post type and taxonomy rewrite structures?
<?php
add_filter('post_type_link', 'client_area_permalink', 10, 4);
function client_area_permalink($post_link, $post, $leavename, $sample) {
if ( false !== strpos( $post_link, '%client_category%' ) ) {
$glossary_letter = get_the_terms( $post->ID, 'client_category' );
$post_link = str_replace( '%client_category%', array_pop( $glossary_letter )->slug, $post_link );
}
return $post_link;
}
?>
When I go to add a new post, `array_pop` throws an error. I believe it is because there is no taxonomy associated yet with the post. !array_pop error
How do I go about fixing this error? I have thought about using `get_post_permalink` as a base because that is where `post_type_link` is hooked into. | In order to avoid an error like this you'll have to check whether or not the value of $glossary_letter is an array or not. Since get_the_terms() returns false on failure, you can just check whether or not $glossary_letter is false and set it to an empty array in order to appease array_pop() without getting that error.
<?php
add_filter('post_type_link', 'client_area_permalink', 10, 4);
function client_area_permalink($post_link, $post, $leavename, $sample) {
if ( false !== strpos( $post_link, '%client_category%' ) ) {
$glossary_letter = get_the_terms( $post->ID, 'client_category' );
// adding check and reset
if ( !$glossary_letter ) { $glossary_letter = array(); }
// continue as you were
$post_link = str_replace( '%client_category%', array_pop( $glossary_letter )->slug, $post_link );
}
return $post_link;
}
?> | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "custom post types, custom taxonomy, url rewriting"
} |
Theme recommendation: Hotel/Hostel/Bed & Breakfast
I searched on different Marketplaces so far, but haven't found anything that wouldn't take me hours or even days to make a wordpress theme from.
### Here's the list of things I need:
**1.** Slider or some photo gallery. Something fancy, eyecatching.
**2.** (Ajax?) Contact Form (minor issue - got some small plugin close to finished)
**3.** Registration/Booking
**4.** Maybe list the already booked dates.
**5.** Any other ideas what might be needed?
* * *
It can be for free or paid. Doesn't make any difference. If you know a theme or just a plugin that solves part of the issue: Tell me. Happy to upvote every single, tiny hint.
If you got search terms that might bring up better results on google or marketplaces, please tell me also. English is not my mother tongue. | For 3 & 4, try Booking Calendar: < I just installed it on a site and it seems to work ok on first impression. It comes with a widget that shows a little calendar that shows dates that are booked, dates that someone has requested, and open dates. It also ships with a request form. It'll send emails when a request is made and when it is accepted or cancelled. I've only done a little testing, so I cannot completely vouch for it. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "plugin recommendation, theme recommendation"
} |
Using jQuery toggle() in WordPress post to show/hide Tweet button?
What is the appropriate way to use jQuery toggle() function in a WordPress post to show/hide a Twitter "Tweet" button?
The problem I am encountering is when I put the code in my content-post.php, the toggle feature and tweet functionality only work on the first (most recent) post in the stream. How would I go about putting this in the Wordpress loop?
Right now, I am including this code my content-post.php file:
<?php if (!is_singular()) { require('post_buttons.php'); }?>
The above code includes the Tweet button from another file with this toggle code:
<script>
jQuery(document).ready(function() {
jQuery('#social_trigger').click(function() {
jQuery('#tweet_button').toggle();
});
});
</script> | If the element that is being assigned the "click" event is "#social_trigger", you cannot have more than one of these elements per page. You are searching for an "id" of an element and by definition, you can only have one element of a particular id per page.
You should change your elements to have a class of "social_trigger" and then change the jQuery to find ".social_trigger". You'll likely have to rework your function a bit, but this should get you past the issue of only being able to toggle the first element. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "jquery, loop, twitter"
} |
Inconsistent bloginfo information
I'm doing a little bit of work on a theme I just inherited from another developer. The site just broke, and I'm trying to fix it.
You can see the site here: www.bowlingventures.com
What's happening is this. As you can see, the home page loads unstyled. All of the images are being pushed out using "bloginfo('template_directory');" If you click on one of the links to another page, you'll see that that page loads correctly. Inspecting the page source, the paths to the image directory differ slightly. Both paths are output using "bloginfo('template_directory');" Additionally, when logged in, the home page loads just fine. How is this possible? Also, I tried adding some information to the header.php template file to be printed on every page. This information was only visible on the non-home pages.
Heads up, the site is _slow_ I'll be fixing that later today. | First thing I noticed is that your secondary pages link to images using a URL like:
`
whereas your home page uses:
`
Not sure this helps, but perhaps this will help someone else figure out what is going on.
Are you sure that the home page is being loaded from WordPress? | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "theme development, bloginfo"
} |
Remove whitespace at the end of posts?
My writer has a tendency to add extra newlines (Enter key) and spaces (space bar) at the ends of posts. Sometimes this results in inches of extra whitespace onscreen!
Is there a way I can make sure extra trailing whitespace is removed when he hits "Update" in the Wordpress post editor? | Quick guess would be:
add_filter('content_save_pre', 'trim');
Add to `functions.php` of theme or wherever is appropriate in your site. | stackexchange-wordpress | {
"answer_score": 6,
"question_score": 2,
"tags": "posts, admin, visual editor"
} |
Getting values from options page to css
i got an options page that needs to affects a certain (for now) css value..
i have about using php variables in css and creating custom global variables in wordpress but havent something easy enough to understand so i have done this and places it in my header file
`<style type="text/css"> .current-menu-item { background: <?php echo get_option('sg_currentbuttoncolor'); ?> !important; } </style>`
does that look like a good solution to you? what is the preffered way of creating changes in my css using values from my options page? | You are doing it correctly. I would suggest two enhancements:
1. Do not put this code directly in header.php. Create a custom function to print the css and hook this into the wp_head action.
2. Always sanitize/escape input before you print it to the screen. Look into ctype_xdigit() for creating a custom function to sanitize you color value. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "css, pages, options, variables"
} |
how to get extra info from checkout in wp-ecommerce
In wp-ecomemrce I have added a new field in the checkout to capture the company name. I need to get the data from the transaction but how? I am not sure how the form fields are stored to be able to retrieve them. | Managed to figure it out. The pdf output code has this to get the normal field values:
$form_sql = "SELECT * FROM `".$wpdb->prefix."wpsc_submited_form_data` LEFT JOIN `".$wpdb->prefix."wpsc_checkout_forms` ON ".$wpdb->prefix."wpsc_submited_form_data.form_id = ".$wpdb->prefix."wpsc_checkout_forms.id WHERE `log_id` = '".(int)$purchase_id."' AND `active` = '1'";
$input_data = $wpdb->get_results($form_sql,ARRAY_A);
The there is a switch statement based ont he unique_name but as this is a custom field it does not have a unique name. I added a loop at the top top loop through and look for the form_field id instead which i got from the database (21 i8n this case) and then I was able to use an if statement to check for the id and output it. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "plugin wp e commerce"
} |
query_post problem
I am running query_post with the following arguments,
<?php $args = array(
'category' => $cat,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'blog',
'post_status' => 'publish' );
?>
$cat = 7 in this instance, it should be returning 1 posts, but it is returning all my posts if they are in any category. | // Category should be 'cat'
<?php
$args = array( 'cat' => $cat, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'blog', 'post_status' => 'publish' );
?> | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "categories, query posts"
} |
Creating a custom menu
I want to create a custom menu in the style below, can this be done? The code in brackets needs to grab the actual page content for each page.
<div class="menu-button-(page-name)">
<a href="(page-link)">(page-name)</a>
</div>
How can I use that one small bit of code to create my menu? That code should generate buttons for 5 pages that are in the main tree in the admin. | <?php
$pages = get_children(array('orderby' => 'menu_order', 'order' => 'asc'));
foreach($pages as $post) {
setup_postdata($post);
$fields = get_fields();
?>
<div class="menu-button-<?php echo $post->post_title; ?>">
<a href="<?php echo get_page_link( $post->ID ); ?>"><?php echo $post->post_title; ?></a>
</div>
<?php
}
wp_reset_query();
?> | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "menus"
} |
WP_query exclude posts of a format
I'm using the code below to try to exclude the format "post-format-quote", but it is excluding all posts, including ones of the standard format (no format).
$myposts = new WP_Query(array(
'tax_query' => array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => array('post-format-quote'),
'operator' => 'NOT IN'
),
'posts_per_page' => 3
)
); | `tax_query` takes an array of arrays. Try this:
$myposts = new WP_Query(array(
'tax_query' => array(
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => array('post-format-quote'),
'operator' => 'NOT IN'
)
),
'posts_per_page' => 3
)
);
Further reading: < | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 0,
"tags": "wp query"
} |
Using Bootstrap in themes
Twitter has just came out with a new web framework called Bootstrap. What's the right way to use it within a theme?
**Update** : The stylesheet inclusion is simple indeed. I want to know which caveats or compatibility issues I should expect. | A few things to consider:
1. Enqueue stylesheets properly, using `wp_enqueue_style()`, and hooked into either `wp_enqueue_scripts` or `wp_print_styles`
2. Enqueue scripts properly, using `wp_enqueue_script()`, and hooked into `wp_enqueue_scripts()
3. Ensure that enqueued stylesheets and scripts are only enqueued on the front end, and not in the admin back end. **Bootstrap and similar frameworks should only be used on the front-end** , and should never be used to override or circumvent core UI in the admin back-end.
4. Use built-in WordPress scripts wherever possible, to avoid conflicts with Plugins, etc. that may be relying on the core-bundled script being used.
5. Consider core image sizes (thumbnail, medium, large) with respect to the Bootstrap media grid
6. Ensure that UI elements such as Menus (`wp_nav_menu()`/`wp_list_pages()`/etc.), Pagination (`paginate_links()`/`paginate_comments_links()`/`wp_link_pages()`), etc. integrate with core WordPress functionality | stackexchange-wordpress | {
"answer_score": 6,
"question_score": 6,
"tags": "theme development"
} |
Count within foreach loop
How can I echo out the count of within a foreach loop? I want to change the class of the div below so it's menu-button-1, menu-button-2 etc etc:
<?php
$pages = get_children(array('orderby' => 'menu_order', 'order' => 'asc'));
foreach($pages as $post) {
setup_postdata($post);
$fields = get_fields();
?>
<div class="menu-button-(insert counter here)">
<a href="<?php echo get_page_link( $post->ID ); ?>"><?php echo $post->post_title; ?></a>
</div>
<?php
}
wp_reset_query();
?>
So I want it to output something like this - `<div class="menu-button-1">` then `<div class="menu-button-2">` and so on each time it goes through the loop. | Insert a new `$counter` variable before the foreach loop starts, and at the very end of the loop, call `$counter++` to increment the number. In the middle, just echo out the `$counter` variable.
<?php
$pages = get_children(array('orderby' => 'menu_order', 'order' => 'asc'));
// Add a counter before foreach starts
$counter = 1;
foreach($pages as $post) {
setup_postdata($post);
$fields = get_fields();
?>
<div class="menu-button-<?php echo $counter; /* echo out counter */ ?>">
<a href="<?php echo get_page_link( $post->ID ); ?>"><?php echo $post->post_title; ?></a>
</div>
<?php
$counter++; // increment before foreach ends
}
wp_reset_query();
?> | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 0,
"tags": "menus, php"
} |
wp_enqueue_script & constants?
I'm enqueuing a script:
wp_enqueue_script('my-script', MY_SCRIPTS."/my-script.js");
How to get MY_SCRIPTS const working in this context?
I know this works:
$template_dir = get_bloginfo('template_directory');
wp_enqueue_script('my-script',"$template_dir/my-scripts/my-script.js");
But I don't like this approach at all. | The value you pass to wp_enqueue_script should be the URL of the script, not the local file path.
wp_enqueue_script('my-script', get_template_directory_uri() . '/my-scripts/my-script.js'); | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "javascript, wp enqueue script, constants"
} |
Using wp_insert_post with WP Network in a cron script
I have network of sites, and I need to import data into them via a cron job. Obviously `wp_insert_post` is meaningless in this case, since i'm not in a blog...i'm in a cron script. I also read that `switch_to_blog` is deprecated, yet I can't find any alternative. How do I set the blog to post to? | switch_to_blog isn't deprecated anymore. You can use it just fine. However, it does have a bit of overhead, so you want to use it as little as possible. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "multisite, wp insert post"
} |
RSS Feed broken
When I try to access my RSS Feed I am getting this error:
error on line 1 at column 35: Unsupported encoding UTF-5
It was working fine just a couple days ago and I'm not sure what I changed if anything to break it. Any Ideas? | I don't know that this has anything to do with WordPress, but I'm pretty sure it should be `UTF-8`, not `UTF-5`. The first line of your RSS feed reads `<?xml version="1.0" encoding="UTF-5"?>`.
**Edit:** Try checking your Reading Settings for the `Encoding for pages and feeds` entry. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "rss"
} |
Way to bulk delete menu items in new 3.x Appearance > Menus system?
I've done some searches but maybe I'm searching on the wrong terms. Does anyone know if there's a way to bulk-delete menu items in the new Appearance > Menus system? This is mostly to clean up localhost installations, so I'm totally open to plugins if anyone knows of one. I'd be thrilled if I could delete a Page and have all its sub pages (the ones I set as its sub pages via the Menu, not necessarily its real Child pages) also disappear from the menu, for instance.
Thanks for any help! | Though I've looked, I have never figured out a way to bulk-delete child pages that were set by hand in the new Menu system. But, I have figured out how to auto-add child page via one of these two plugins:
* Gecka Submenu
* Add Descendants As Submenu Items
If the child pages are auto-added via one of these plugins, I believe they call all be deleted simply by removing the parent page item or disabling the auto-add pages.
Hope this helps someone else who's struggling with managing large numbers of menu items (especially after the import process duplicates all of them!). | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 3,
"tags": "menus"
} |
Display a tag only if there is a description
I'm building a site glossary and trying to display only tags with descriptions. Is there a way to determine if the description is available and only display the tag when it is?
Here is where I am so far.
$tags = get_tags();
if (tag_description($tag->term_id)) {
if ($tags) {
foreach ($tags as $tag) {
echo '<dt><a href="' . get_tag_link( $tag->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $tag->name ) . '" ' . '>' . $tag->name.'</a></dt><dd>' . tag_description($tag->term_id) . '</dd>';
}
}
} | The object returned by `get_tags()` should have a `description` property, so you don't need to try to get it again. Just check to be sure `$tags->description` isn't empty. You should probably also reorganize so that you don't do anything at all unless `if($tags)`. Thus:
// Get ALL the tags!
$tags = get_tags( array( 'hide_empty' => false ) );
if ($tags) {
foreach ($tags as $tag) {
if ($tag->description) {
echo '<dt><a href="' . get_tag_link( $tag->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $tag->name ) . '" ' . '>' . $tag->name.'</a></dt><dd>' . $tag->description . '</dd>';
}
}
} | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 0,
"tags": "taxonomy, tags, description"
} |
Will these plugins work with wp multisite?
I just created my first network of sites with wordpress and I was installing plugins, I installed these:
> Platinium SEO Pack (
>
> TubePress (
>
> Contact Form 7 (
>
> Social Bookmarks (
>
> Strictly Auto Tags (
>
> SEO Smart Links (
>
> SEO Friendly Image (
>
> Google XML Sitemaps (
I "network activated" all the plugins and then I went to one of the sites dashboards, and I saw a msg from Google XML Sitemaps saying that the plugin doesn't work on multisite. Now my problem is that I don't know if the other plugins will work.
Will I have to test each feature of all the plugins or is there an easier way to know if they work on multisite? | Use this plugin for google sitemap.
For others do not network activate those plugins. Goto individual site and activate it manually. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "plugins, multisite"
} |
How to find the post_id of a post on a wordpress blog that uses pretty URLs?
The only trick here: It is not my blog, I know how to do it using php in my blog. I want to find the id of a post on another wordpress blog through the internet. Does this information 'leak' somewhere, is it possible to be found by a third party? | Most themes that I've seen use the post ID as the ID of the wrapping div for a post on the home page, archives, single post, etc. For example:
<div id="post-1920" class="post [...]">post content and meta</div>
So you could parse that with a regex or using something like Simple HTML DOM.
But again, this is theme-dependent. It may not work 100% of the time.
Also, on the single post page, if there is a comment form, there should be a hidden input with the name "comment_post_ID" that contains the post ID. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "permalinks"
} |
ReWrite rule for files of a previously standalone blog moved to network
A moved a standalone wordpress install to be one of a network, but the possibility to access the uploaded files with the same URL is need to be kept.
I'm trying to get the following rewrite rule to work, without success:
RewriteCond %{HTTP_HOST} ^(.*)?domain\.com
RewriteRule ^/wp-content/uploads/(.*)$ /wp-content/blogs.dir/3/files/$1 [L]
What do I miss? | OK, I've found it by testing all of the combinations, I could imagine:
RewriteCond %{HTTP_HOST} ^(.*)domain\.com
RewriteRule ^wp-content/uploads/(.*)$ wp-content/blogs\.dir/3/files/$1 [L] | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "url rewriting, rewrite rules, multisite"
} |
password protect individual pages
Is it possible to password protect individual pages with Wordpress? What I'm trying to do is have special pages suche as somesite.com/project1 which has a username and password that I can set, but somesite.com/project2 has a different username and password.
And so on and so forth, with new usernames and passwords for new pages created down the line.
Thanks in advance! | You can password protect individual pages and posts. Under the Publish section of the dashboard, look under the link for **VISIBILITY**. The default setting is PUBLIC, but you can change it to PRIVATE, which only you can see when you're logged in, or PASSWORD PROTECTED, which requires you to enter a password when you are posting the page/post, and for the reader to enter the password to view the content. Using this method, there is no username but you can control visibility
An alternative would be to use a membership plugin, which requires an individual user to log in, where you control their access to areas of your blog/site and what documents they have access.
Link to Membership Plugins in the Codex | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 2,
"tags": "login, password"
} |
Two embedded gallery in one post
I've a nice question for you.
Is there an easy way, to embed two galleries in the same post? I refer to the wordpress embedded gallery. Using a plugin of-course.
Is there outside a plugin other than Easy Gallery Manager that can accomplish this goals?
Must I write a new plugin? | You can create two different posts, each containing a different gallery. These can be drafts or private or whatever.
Then you can include their galleries into a different post by specifying their post IDs in the gallery shortcode.
`[gallery id=123]` | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 3,
"tags": "plugins, gallery"
} |
Add a reset button to the options page (using Settings API)?
How do I add a reset button using the Settings API?
I use
add_settings_field
To add a field...is there a hook to add a reset button? | I asked this Q some couple of month myself. You don't need a hook or anything like that. Just remove the options you added to the DB, then add your defaults.
If you need just the button function: `submit_button()`; | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "plugin development, reset"
} |
Remove "attachment/" from the URL of attachment pages
Currently, the media for a page on `/hello-world/` is shown on `/hello-world/attachment/image-name/`. Is it possible to remove `attachment` from this URL, and make it `/hello-world/image-name/`? | Don't include %category% anywhere in your custom permalink string, then it won't need the "attachment" text. Also, don't use numeric slugs for the page/post name. Same basic problem occurs there. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "permalinks, attachments"
} |
Sorting tags by name
I'm displaying a lit of tags when they have a description. I'd like to sort them by name instead of by post quantity. Is there a way to do this?
<?php
$tags = get_tags();
if ($tags) {
foreach ($tags as $tag) {
if ($tag->description) {
echo '<dt><a href="' . get_tag_link( $tag->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $tag->name ) . '" ' . '><h3>' . $tag->name.'</h3></a></dt><dd style="margin-bottom: 10px;">' . $tag->description . '</dd>';
}
}
}
?> | You should use the function **wp_tag_cloud** , it has many parameters as described in the codex and the one to sort the results as you want: `'orderby' => 'name', 'order' => 'ASC',`. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "taxonomy, tags, sort"
} |
How to keep theme layout the same when admin gray bar is present?
When I am logged in, there is a gray admin bar on top. My theme layout got distorted by the bar. How to solve the layout problem? Is there a function that can detect user is logged in or not, or use CSS can solve the problem ?
The theme demo is at: < and below is the screenshot when the gray bar is there.
p.s. I use `WordPress 3.2.1` & plugin `Theme Test Drive`
!when the gray bar is present... | The top bar of your theme is also positioned absolutely, so it doesn't know to come down. You can use `is_admin_bar_showing()` to check to see if it's showing, and then I'd probably just inject some styles using `wp_head` to move it down, since it's very little CSS.
All told, you'd get something in your theme's `functions.php` like:
add_action( 'wp_head', 'prefix_move_theme_down' );
function prefix_move_theme_down() {
if ( is_admin_bar_showing() ) {
?>
<style type="text/css">
#header { top: 28px; }
#content { margin-top: 68px; }
</style>
<?php
}
} | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 2,
"tags": "theme development, css, admin bar"
} |
Adding labels to Setting titles with API
If I add a setting using `add_settings_field()`, it doesn't create a `<label>` around the title so that it can be clicked to focus on the field. Some of the core settings do this, but they just add it in the raw HTML rather than using the settings API. Is there any way to add labels with the settings API? | You need to pass last parameter `$args`, if you want `add_settings_field` to output `<label>` use `label_for' argument, see code snippet below
<?php add_settings_field( 'my-id', 'Test Filed', 'mamaduka_test_field', 'general', 'my-section', array( 'label_for' => 'my-test-field' ) ); ?> | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 2,
"tags": "settings api"
} |
Blog.php or how to display recent posts?
I created a home.php which doesn't display the recent posts in the standard-blog-style. Just have a look at my website to see what I mean. I want to create a link that leads to something like " where the recent posts are displayed "normally". I know how to do that, but what I don't know is how to create that new "link" that leads to ".../blog".
Is it possible to create a "blog.php" just like a "home.php" where the recent posts will be displayed?
But even if I create a "blog.php" I will get a 404 error message when clicking on "
I hope you get what I mean and can help me out here a bit. Do I have to modify the htaccess thingie for that or what? :/
Thanks a lot in advance :) | Don't use `home.php` for static home page, use `front-page.php` or any other page template instead.
Also see Codex page for Creating a Static Front Page | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 3,
"tags": "htaccess, blog page, linking"
} |
WordPress Theme Preview Image
I'm developing a custom WordPress theme. When I go to select themes in the Appearance menu, my theme does not have a preview image. Is there something I need to do to get a preview image to show up? I can't find any resources on the web that talk about this. Maybe I'm just searching the wrong thing though...? | There is no automatic preview. You need to create the screenshot yourself and place it in the theme/child theme folder named screenshot.png
The recommended image size (currently) is 1200px wide by 900px tall, however the screenshot will only be shown as 387x290. It is over-sized to allow for high-resolution viewing on HiDPI displays. Note that as of version 4.7.4, the bottom ~18% of this image will be cutoff so keep logos or other graphics centered.
For the latest info see: < | stackexchange-wordpress | {
"answer_score": 41,
"question_score": 30,
"tags": "theme development, images, previews"
} |
Fetch Google Calendar in a custom way
I have to integrate the next upcoming events from a Google Calendar. Just a custom list of the events with a few CSS-enhancements to style the date and the title. Is there a way to do so? I checked plugins etc but I don't find solutions to integrate it in my theme. Is there a way to do this with the rss-feed?
Thank you! | See amr-iCal-events-list at wordpress.org
Uses ics file as input
Has some default lists or can totally customize own, has widgets or shortcodes. Can switch off default CSS and/or add own css | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "calendar"
} |
Is wordpress good enough for ecommerce?
I'm familiar with Wordpress and some e-commerce back-ends like Magento, etc. I think I could build it with these, but I got advice not to do this as it will be hard to scale in the future. Should I listen to them?
Also, I will need custom features like custom product pages, user profile pages, voting elements, file uploads. Will I abe able to implement such features and more with wordpress? | That's all possible with Wordpress, and you have several choices. E.g. WP E-Commerce or Jigoshop etc
Scale-wise, it depends exactly what you're wanting in terms of scale, initially and eventually. Wordpress can be manipulated to scale quite far, you can buy a bigger server, shift a large chunk of your content and pages into the cloud, appropriate caching and server setup, and the right plugins, can go a long way.
Your biggest issue if you code your theme correctly and set everything up, will not be server horsepower, it'll be network bandwidth, and that's not unique to Wordpress. The same issues will arise using Magento or Lemonstand etc | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "e commerce"
} |
Custom query Custom-Post-Types creates error
I created a custom-post-type for members of a firm. On the start-page I tried to call them via custom query but it shows an error. Heres my code: < and the error says: Call to a member function get_queried_object() on a non-object in /www/htdocs/w00e3b6a/hosting/basecamp/wp-includes/query.php on line 43
What did I wrong with the query? | just use
query_posts('post_type=team-member&posts_per_page=2&paged=$paged');
instead of
$wp_query = new WP_Query( array(
'post_type' => 'team-member',
'posts_per_page' => 2,
'paged'=>$paged
) );
and then the while loop as
if(have_posts()) while(have_posts()) : the_post();
instead of
<?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?> | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "query"
} |
Combining these queries? (Same taxonomy term + same category as post)
I´m not to good at coding so I could use some help with this! I have a single page which below the post shows more posts from the same category. Then I have another single page which in a similare fashion shows more posts from the same taxonomy term as the current post.
I would like to combine this to show posts from the same category and taxonomy term as the current post.
Code for "same taxonomy term": < Code for "same category" : <
If someone would help me with this I would be very grateful! | Simply add the `'category__in' => $category_id_array` argument from your second query inside your first query.
If this doesn't work, make a tax_query, with both `kund` and `post_category` taxonomies | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "categories, taxonomy, terms"
} |
Cannot post comments if I don't post a website?
I have a severe problem with my comment template. For some reason comments won't show up unless somebody also clicks on the website field. It's not necessary to actually post a website, but you have to click on the field, otherwise the comment just won't show up. Here's my website so you can try yourself.
Here's my comment.php: < And here my comment-template.php (which I haven't changed but maybe a plugin did): <
Any ideas? :( I already tried various things modifying my comment.php, but nothing worked.
Thanks a lot in advance. | Try changing line 152 in your comments-template.php file from:
if ( empty( $url ) || ' == $url )
to `if ( empty( $url ) || ' == $url || 'Website' == $url)` | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "comments"
} |
Using Magic Fields Image-Uploader with Thumbnails
I use Magic Fields a lot to give my clients and users the ability to upload specific content to their websites. Is there a way to call images by their size? At the moment I just put out the images, the persons uploads. But right now I need a solution that gets a specific size from the uploaded picture.
I know that Magic Fields uses the default Image-Uploader by wordpress which creates predefined sizes by default. Is there a way to get those sizes while calling the magic field with the uploaded image? | Magic fields doesn't necessarily attach images to posts when uploaded via the WP image uploader, and it's not so simple to get the ID associated with an image. The plugin has its own function to retrieve different sizes:
$image_attributes = "w=250&h=150&zc=c&q=90"; // 250x150px, crop to center, quality 90
echo get_image('my_field_name',1,1,1,NULL,$image_attributes);
New sizes are generated on-the-fly and then cached for future use. See get_image() in Magic Fields wiki. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "plugin magic fields"
} |
Making a particular kind of search engine with Wordpress?
I would appreciate if I get to know details and how-to make a particular type of search engine with Wordpress,where users can submit/showcase their product and submit their listings of products.It would be a user submitting site. | Look for business directory plugins in the WordPress repository. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "plugins, customization, plugin recommendation, repository, search engines"
} |
Storing image gallery plugin data
I'm making image gallery plugin and I'm not sure what is the best way to store data in WordPress. Plugin can contain multiple gallery instances with some options and each gallery contains images with options. Gallery can be added to site using simple shortcode, something like this: [mygallery id="gallery1"].
So should I use add_option() and store all data in one field or just create two tables for galleries and gallery items?
Thanks for advice. | Depends on what you want to store.
* The Settings API uses it's own, well performing, engine behind Tutorial
* You can (miss)use the Theme modifications API as well
* Or, if it you're talking about adding data to posts, you can use the Post Meta Storage Engine
_Note: "Post Meta Storage Engine" is no official term. I just used it to surround/house the public API/functions set in a nice name._ | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 2,
"tags": "plugins, gallery"
} |
Map clashing with WP - suggestions on fix?
I've followed this tutorial - < to create a state map of USA which you can see here - <
I downloaded the source files and got it all working locally then uploaded all the files to the link above. It's almost working but the hover doesn't seem to work when you hover over each state. I had this working locally but cannot work out why it's not working online.
One cause may be that Wordpress (that's what the site is built on) is blocking something along the way.
Can anyone help?
UPDATE: It's blatantly something clashing with Wordpress as it worked locally, does anyone have any idea's of how to fix it? | If you're using FireBug for FireFox or the Google Chrome Developer Tools (both available on Win via [F12]-key), then you can see that you're missing ressources (404) via your Console Tab in the tool bar:
> Failed to load resource: the server responded with a status of 404 (Not Found)
The list of "missing" files:
* tooltip.css
* mapper.js
* wz_jsgraphics.js
* cvi_tip_lib.js
* maputil.js
When looking at your source than I'd say, your pathes are simply wrong.
Try to use `plugin_dir_path( __FILE__ );` for javascript file pathes and `plugin_dir_url( __FILE__ );` for stylesheets. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "html5, map"
} |
Large taxonomy (2000+ terms), causing WordPress to hang
I have a large taxonomy (and about to grow a lot larger) with several thousand terms in it. When I'm editing a post, there is now a significant hang when it goes to load the term list.
Has anyone run into this before? Any suggestions for dealing with such a large list? | This is probably because your taxonomy is hierarchical, and the default meta box for such taxonomies is similar to the category box - which displays all terms as input elements. So the browser lag for thousands of elements within a page is expected in this case.
If you can't make your taxonomy non-hierarchical, try removing the default meta box and create your own, in which you display only the most used terms, a single input field with autocomplete or something similar | stackexchange-wordpress | {
"answer_score": 9,
"question_score": 4,
"tags": "custom taxonomy, terms"
} |
How can I assign a specific id to the last comment of a post
I am fairly new to Wordpress and I am currently designing a template for a client of our company. However, I need to assign a specific id to the last comment of a post.
Basically I have my own function that is called on the callback of `wp_list_comments()`. this is due to the fact that I have a very customised comment layout.
Now, in the functions.php I would like to assign simply with an if statement such as
if ( is_last_comment() ) : print "last-comment" endif;
I have looked here and in the codex and on other pages and I cannot find anything.
I appreciate anykind of help.
Thank you very much in advance. | I guess you use the comments loop(?). If so, you could
### Possibility A
`count` the comments first, set `$i = 0;` before the loop and `$i++` at the beginning/inside the loop and then attach your needed id when `if ( $count < $i ) $css_id = "id='last-comment'".
### Possibility B
You could take the comments object(?) and use `$last_comment = count( $comments_obj );` and after the loop `echo $comments->$last_comment;`. If it's an array, you should use `echo $comments[ $last_comment ];` of course.
* * *
Not sure which one works as I haven't dealt with comments for a while, but it should get you on the right track. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "comments"
} |
How to change post to page
If I have to change a number of posts to pages, does this require anything more complex that setting the post-type to page on the table wp_posts? Do any other settings need to be changed.
Is it better to use a plugin like Convert Post Types or Vice Versa instead? I have a number of posts that I like being able to categorize on a site, but I may need to change to pages in the future.
Thanks, | Yes Its Possible Just Simply Run This Query Once If You're Not Developer Then Don't to Anything Just Simply log in to your cpanel->open phpmyadmin->There is maybe one or more database you've to find which one is wordpress database (click on database and where all table names starts with "wp_" its your Wordpress Database -> and check there's few tab "browse / structure /SQL" Go to SQL Paste this Code write below and click on go you're done now.
UPDATE `wp_posts` SET `post_type`='page' WHERE `post_type`='post' | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 4,
"tags": "posts, pages"
} |
WordPress.com-registered domains
I got the client who paid for WordPress hosting with wordpress.com. They also purchase domain with wordpress.com but we did completely new WordPress installation on another server and would like to now re-point that domain to another IP address is that possible? I have a option inside that WordPress installation to Edit DNS Record but when i try to put my IP address like they suggest: A 1.2.3.4 its coming up with an error: We can't save these records because they don't look right to us. Check the errors below. Please contact support if you are unable to resolve the problem.
Can any one help or advice.
Many thanks, | Check this out: <
It looks like you can just change the name servers/a records/whatever. But if your client is not planning on switching back to WordPress.com, I would suggest you transfer to another registrar. It looks like the Automattic domain manager is pretty full featured, however, so maybe that's not necessary. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "wordpress.com hosting, domain, domain mapping"
} |
How do I query multiple specific posts from a custom taxonomy?
WordPress 3.2.1. I want to query several specific posts that are part of a custom taxonomy. This is what my query looks like for retrieving one post, using the id for that post.
$args = array(
'post_type'=> 'portfolio',
'skill-type' => 'the-letter-d, food, kids-meal',
'p' => 56
);
query_posts( $args );
This works for just getting one post, but I'm looking to get multiple posts. I've tried using 'post_in' => array(56,40,7...etc) in place of 'p'=> 56 and it didn't work. I'm assuming that doesn't work with custom post taxonomies or else I am just doing it wrong?
I've also tried using the following, removing the terms list since it's not really needed.
$args = array(
'post_type'=> 'portfolio',
'post_in' => array(56,40,7)
);
query_posts( $args ); | If you are retrieving post(s) by ID, then why do you need terms in query? Post IDs are unique. You likely need post type (because it's not default), but taxonomy terms only add confusion to the mix.
**Update**
Noticed after you added second code sample - `post__in` has two underscores in it, your examples lack one more. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "custom taxonomy, query posts"
} |
comment_post callback function: how to run it in the background.
I'm calling a custom function when someone submits comments using the following to plug into the comment_post action: add_action('comment_post', 'MY_FUNCTION');
The problem is that my function is extremely heavy, causing about a 5 second delay between the time when someone submits a comment to the time when the page refreshes and they view their comment. Is there any way that my custom function could run in the background, so that they could be redirected right away? Alternatively, would it be safe to redirect them directly at the top of my function, then run the rest of my function after they had already been redirected? | If you're sending a redirect, then you can also just close the connection early and continue processing.
wp_safe_redirect('
header("Content-Length: 0");
header("Connection: close");
flush();
do_something(); // continue processing whatever, user is already redirecting by now
Reference: <
Read those user comments carefully, there's some caveats there. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "actions"
} |
Run JS after widget settings are saved?
I've written a small widget that uses JS for setting up some tabs in the settings panel. Is there a way to re-trigger the tab JS when the widget is done saving?
Looking at the WP JS source it doesn't look like it, as it simply blows away the existing HTML & re-renders the entire form. I could potentially overwrite `wpWidgets.save` & do something nutty there but that seems really drastic.
**Solution**
After some hacking based upon One Trick Pony's idea, here's what I ended up with.
<script>
jQuery(document).ready(function($){
if(parseInt("<?php echo $this->number; ?>", 10)) {
$("[id$='<?php echo $this->id; ?>'] .tabs").tabs();
}
});
</script>
Basically I just send down some JS w/ some Widgets values hardcoded in & do some checks & fun CSS3 selectors to find the right DOM nodes. | Put your javascript code inside the widget form, and it will be triggered whenever the widget is refreshed.
If you're tabs are hooked on a click event, a better way would be to use `$.delegate` on the widget instance wrapper. That way you don't need to include the js inside every widget instance... | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "widgets, javascript"
} |
Creating Tables on Network Activation
I'm working on a plugin which creates a new table. I've got it working fine on a single site install, but I'm not so sure about multisite.
How do I create a table for each blog on network activation? | I would actually advise against doing that.
If you create a table for each blog on network activation you'll start running into scalability issues. Some Multisite networks are small (2-10 sites) and wouldn't cause too many issues. But larger networks (1000+ sites) would add a _lot_ to the database if they added their plugin.
Instead, I'd recommend creating a _single_ table and adding a "blog_ID" column to the table. If you're running a single site installation, just set that column to be 0 and run everything normally. But on a Multisite installation, set that column to whatever blog is using that data.
A single table is easier to manage.
Besides, if you create a new table for each blog, not only do you need the massive creation script when first activating the plugin, but you need to hook into the site creation mechanism to create a new table whenever a site is created. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "plugins, database"
} |
Replace TimThumb in existing WordPress Themes
I'm sure most are aware of the most recent Timthumb issues. I know they have put a band-aid on the problem, but I really don't care for the script for several reasons. Before I started building my themes I purchased several from various markets. I'm trying to figure out the best method for removing Timthumb and replacing it with something else.
I've successfully replaced it for one theme using the_post_thumbnail, but it was quite a bit of work. I'm just curious if someone knows of a better method. As it stands now, I have to weigh the time it will take using my method vs. how much do I actually like the theme. Can you provide any suggestions or links to proven articles? | You have three options here:
## Use `the_post_thumbnail()`
You say you've already done this with one theme. This is really the best solution because it keeps everything using core code (which is frequently updated) rather than third-party libraries.
## Upgrade TimThumb
Since the "most recent" issues, they've released a new version of TimThumb that corrects the security vulnerabilities. Merely replacing the old system with the updated, secure one should be the quickest path to resolution.
## Email the developer
If you're using freely-available themes, you're out of luck and might be stuck fixing things yourself. If you actually purchased the themes from someone else, please email them and ask that they release an update.
It's not really their responsibility to provide a security update, but most quality developers will jump at the chance to update their code to prevent huge security holes. Besides, it never hurts to ask. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "customization, timthumb, thumbnails"
} |
Whats the difference between blog_info('stylesheet_url') difference get_stylesheet_uri()
The question is in the title really. What is the difference between blog_info('stylesheet_url') difference get_stylesheet_uri(), and if it's a case that one is newer then which.
The codex says:
> 'stylesheet_url' - Returns the primary CSS (usually style.css) file URL of the active theme. Consider using get_stylesheet_uri() instead. | Actually `bloginfo( 'stylesheet_url` ) uses `get_stylesheet_uri()` function, so there is no difference. `get_stylesheet_uri()` is newer | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 3,
"tags": "plugin development, theme development, codex"
} |
Show Homepage (only) Hits Count
I need a counter to put in my theme (using php) or widget to show homepage view counts I've tried "Cystats" but i couldn't get 'only' homepage hits by it how can I do this ?
(there is a idea to show how many times website has been opened -sessions counts- for example- but i couldn't find any counter to do that , it's ok to find a way to show that instead of homepage counts) | Add the counter (PHP or otherwise) to the template file for the home page. This will be either `home.php` or `index.php` depending on how you have things set up.
If you want to instead add it in the footer, enclose the code inside a conditional tag to detect whether or not you're on the home page:
if( is_front_page() ) {
// ... put your tracking code here.
} | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "plugins, templates, statistics"
} |
Search input area autogrow - how?
I've tried for many hours to style my searchform. I managed to get it all done after some research. I even managed to get the text highlighted when on focus using javascript (no idea if there's a non-javascript solution as well). anyways, I've been googling around and trying out all sorts of things (e.g. playing around with the width when "onfocus" in my style.css) - nothing worked. I want a width autogrow for my searchform like in the Twenty Eleven Theme. Basically what I want is when you click on the input area the it will get a bit wider.
What I could find was this plugin which uses jquery. I don't know how to implement it, though. Is using jquery the only option I have? Can I get this effect via a different method?
I really tried a lot and searched around for hours, but couldn't find an answer, so I'd be happy for any kind of advice you can give me :)
Thanks a lot in advance! | they're using CSS3 transitions.
<style type="text/css">
#s {
float: right;
-webkit-transition-duration: 400ms;
-webkit-transition-property: width, background;
-webkit-transition-timing-function: ease;
-moz-transition-duration: 400ms;
-moz-transition-property: width, background;
-moz-transition-timing-function: ease;
-o-transition-duration: 400ms;
-o-transition-property: width, background;
-o-transition-timing-function: ease;
width: 72px;
}
#s:focus {
background-color: #f9f9f9;
width: 196px;
}
</style>
<input type="text" class="field" name="s" id="s" placeholder="Search"> | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "jquery, javascript, search"
} |
How to reverse engineer the Twenty Eleven background image uploader?
I'm searching through the twenty-eleven theme's source files (functions.php and theme-options.php) attempting to get some clues on how to implement the upload utility found on several of the theme options pages. However, I can't find any reference to it.
Anyone know which file its contained in? | for the custom background, you'd call `add_custom_background`, for the cool header image things, it's `add_custom_image_header`. You need to hook both those into something like `after_setup_theme`:
<?php
add_action( 'after_setup_theme', 'wpse27586_setup_theme' );
function wpse27586_setup_theme()
{
add_custom_background();
add_custom_image_header( 'some_callback_for_front', 'some_callback_for_admin' );
}
Add custom image header is more complex than it seems, so take a look in Twenty Eleven's `functions.php` file inside the function `twentyeleven_setup`, which starts around line 75, for some how to. The code is very well commented. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "theme development, theme twenty eleven"
} |
Any recommendation on how to manage ads?
I am in the process of creating a network of >40 sites with wordpress, and I am trying to put together the base that each site will use, for example all the sites will use google analytics so I will use this < plugin for that. For sitemaps I will use < etc. (These plugins works well with wp multisite)
All the sites will use google adsense, so I was wondering if someone knows some plugin or something that will help managing the ads directly from the dashboard, taking in count this will be a multisite environment.
I browsed the wp plugins directory but I didn't find anything good, I'd like to hear if someone is already using something for managing ads and such. | Try using AdRotate, it's quite good. You can define block of ads that are displayed randomly (at will) at each page load. You can define single ads and the put it in your theme.
You can paste the adsense code in the blocks, and you can manage all the aspects from the backend.
Give it a try. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "plugins, multisite, ads, adsense"
} |
Best Browser for Editing Posts
What browser is best supported by Wordpress.org for editing posts in the visual editor (which I guess is TinyMCE)?
I use Google Chrome and have run into issues which are specific to just this browser. Here's an example bug. | TinyMCE is generally cross-browser compatible. However they provide the best support for IE, Firefox and Safari. I've never ran into problems with my beloved Opera too.
<
If there are any bugs they're mostly not browser-dependent, but if they are - try Firefox, Safari, Opera, IE - in that order. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "tinymce, editor, visual editor, bug, browser compatibility"
} |
wp_enqueue_style in Plugin
> **Possible Duplicate:**
> Where is the right place to register/enqueue scripts & styles
When I enqueue a css style in a plugin like so:
function add_my_stylesheet()
{
wp_enqueue_style( 'myCSS', plugins_url( '/css/myCSS.css', __FILE__ ) );
}
add_action('init', 'add_my_stylesheet');
Is 'init' the correct action to use? It works fine. Is there any reason not to do it this way? Is this the standard way? I want to follow the best practices.
Thank you.
-Laxmidi | You can use `admin_print_styles` for your hook, this is the preferred method for adding a style to your plugin or admin page.
add_action('admin_print_styles', 'add_my_stylesheet'); | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "plugins, css, wp enqueue style"
} |
Page Name and Permalinks
I am using WordPress 3.2.1 and just added a page to my site called "Centre Management", which in turn created a permalink:
<
for that page I just created.
After this, I trashed this page and wanted to start again. So when I now create another new page with the same name as above, i.e. "Centre Management", WordPress now creates me a permalink of:
which is not what I am after. I would like it to appear as:
<
Can you please let me know how I can go about preventing these sequence numbers appearing after I recreate a page with the same name?
I would always like to to use the page name only.
FYI, I have a .htaccess file and am using the following Permalinks structure in my sites:
Custom Structure: /http:/localhost:8888/mysite/post-name/
Any help would be much appreciated.
Thanks. | You have to permanently delete the post from the trash to be able to use that permalink again.
At the top of the pages list, where it says All, Published, Trash, click trash and then select permanently delete link for that page. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "permalinks"
} |
What's the best way to implement custom widgets on a per post basis?
I'm creating a category called "Falculty" where each post is a member of my client's staff. Each post includes a biography and photo gallery of that staff member. My client would like to be able to add Twitter, Facebook, and Youtube links/feeds to their individual profiles.
What would be the best way to handle this to ensure that it's future proof? I'd like them to be able to easily add or remove these social media references at will.
I know little about adding widgets to posts/pages other than doing it on the front page. Is there a plugin that will allow me to do this? Should I use custom fields instead?
Any and all help will be greatly appreciated. | > Twitter, Facebook, and Youtube links/feeds to their individual profiles.
Those links/feeds are meta data for posts, so postmeta is the place where you should store them. Easy way to add meta data to posts is Custom Fields, also you can create and use meta box for this purpose.
Here is tutorial for creating meta boxes: < | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "custom field, widgets"
} |
Google Plus One script has quit working, now returns red flag
Here's the Google Plus One script I've been using:
<g:plusone a href="<?php echo urlencode(get_permalink($post->ID)); ?>"></g:plusone>
Worked fine until it didn't. Now it's returning a red Plus One button with a bunch of suggestions to correct the error, none of which apply.
Tried out the Plus One plugin, which works on single posts and pages, but screws up on custom post type pages. I'd rather not use a plugin.
Does anyone have a Plus One script that will work consistently with WordPress?
Thanks. | Here's the answer, courtesy of a sympathetic Google employee:
<g:plusone a href="<?php echo get_permalink($post->ID); ?>"></g:plusone> | stackexchange-wordpress | {
"answer_score": -1,
"question_score": 0,
"tags": "theme development, google plus"
} |
Duplicate a Wordpress Install for Testing Purposes
I want to test some plugins on my Wordpress site. However, I do not want to mess anything up. Is there a way to duplicate my Wordpress site to a new directory so that I can test plugins there before I push them to the main site? | I sometimes use this plugin
<
it works pretty well if your server enviroment meets it's requirements.
Otherwise, it's the good ole, mysql dump route that the other guys explained. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 2,
"tags": "testing, duplicates, sandbox"
} |
Is there a plugin that pushes posts to your Google+ profile?
A Google+ equivalent to Simple Twitter Connect that pushes every post you make to your G+ profile - does such a plugin exist? | Such a plugin does not yet exist because Google does not have a public API that allows for such third party integrations. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 3,
"tags": "plugins, google plus"
} |
Simple spam check for valid domain in commenter's email address
Many times commenters leave fabricated email addresses. As a really basic step, is there a plugin that checks to make sure that the domain actually exists? | The problem is not if it exists, after all I can sign up with [email protected] , it's fake and the domain obviously exists.
The only real way to verify is to send an email to the address and have an action that they click. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "comments"
} |
Plugin to create unlimited custom shortcodes?
I want to be able to create unlimited shortcodes and use them anywhere on my theme, pages or posts.
The idea is:
A textfield for the shortcode name. A textarea for the shortcode content (html+js).
I found this one: <
But it's really old and outdated, I am using wp 3.2.1 with multisite.
Does someone knows if a plugin like this exists and it's compatible with wp 3.2.1 and the multisite feature? | Try one of these:
* Shortcodes Pro
* Shortcode Manager
* Shortcode Exec PHP
* Shortcoder | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "plugins, multisite, plugin recommendation"
} |
Add image attachment to post via coding?
I tried to add an image as Attachment image to a post. in `wp_postmeta` i added `_wp_attached_file` as `meta_key` and `value = productimages/Routers/v/CISCO1941.jpg` it not works and i could not see the image as attachment! but when i use add image button in wordpress's HTML editor, it add exactly this field to that table but with a different post ID!
is there any dependency for that field? screenshot from db: | You do not add image attachment **to** post. In WordPress image attachment **is also** post. See post types in Codex.
* what is usually called _post_ on surface is technically post of `post` post type.
* image attachment is a post of `attachment` post type.
So what you need to do is to create image attachment (using `wp_insert_attachment()` and couple more related functions) and set your post as parent for it. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "attachments, gallery, images"
} |
Add Meta box Befoure Post Title
i would like to add an image above the post title... in the old days i would change that directly in wordpress code but thats not very affective.. you know, upgrades and such.
is ther a way using add_meta_box or some othere way to add a box directly above the post title?
tried this Priority of Meta Box for Custom Post Type
BUt that didnt work.. help Please :) | The only _real_ chance you got is to hook into `admin_notices`, which is above the post-new.php page title & icon:
function wpse27700_above_title_content()
{
?>
<style>
/*
You might need to attach some styles here,
to not get into the admin notices styles
*/
</style>
<h1>TEST</h1>
<p>This is a test message</p>
<?php
}
// This is needed to only hook on the post new & edit screens.
function wpse27700_admin_head()
{
add_action( 'admin_notices', 'wpse27700_above_title_content', 9999 );
}
add_action( 'admin_head-post-new.php', 'wpse27700_admin_head' );
add_action( 'admin_head-post.php', 'wpse27700_admin_head' ); | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 4,
"tags": "metabox"
} |
Set Maximum Width for an uploaded image
I want to restrict the width to a maximum of 600px for images uploaded using the "full size" image option in WP posts/pages section.
I've tried two methods:
**Method 1:**
Adding the following to style.css of the theme:
.post img {
max-width: 600px; /* Adjust this value according to your content area size*/
height: auto;
}
**Method 2:**
Adding the following to the top of functions.php:
$GLOBALS['content_width'] = 600;
Both of them are not working. The option for full-size is not available in **Settings > Media**
Please help. | Fixed my problem usinng < | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "media, uploads, images"
} |
SHOPP Custom Post Type, conditional tags
I really want to find out what the Custom Post Type is for the SHOPP plugin - is there any way you can fish it out from WP in the code or in the admin? May come in useful to customise other plugins and such.
This is specifically for SHOPP plugin right now, so if anyone knows what it is (or if it has one?!) that would be helpful.
Cheers! | Look in your database, it'll be in the posts table under the `post_type` column for each product.
Or alternately- search the plugin files for calls to `register_post_type`.
Or depending on how the plugin works on the admin side, the URL of the edit screen may tell you: `edit.php?post_type=some_post_type` | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "custom post types, plugin shopp"
} |
how to show all post with its contents
i have "favorite-film-video-songs-super-scene-climax" category and i want to show all of the post with contents(which is youtube video) for every post.
in below link i want to show all post with respective youtube video( like click one particular post it will show youtube).
like this i want to make for this all post.
here missing is all post's youtube video respective.
thanku. | The theme determines whether to show excerpts or full content on archive pages (e.g. the cateogry listing), and since you're on WordPress.com, you'll probably have to change themes to one that shows the full content on archive pages. There's a listing here, don't know how complete it is: <
You might also try putting the HTML code for your video embed in the excerpt box and see if it shows up that way. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": -1,
"tags": "posts, categories, archives, youtube"
} |
How to check if txt file exists inside template folder?
I have a folder inside my theme where I hold some txt files which I am including in a theme. The problem is that before including txt file I need to check if it does exist. I fail checking it the following way and have no idea why it wont work, always returns false.
$themeLocation = get_bloginfo('template_url');
$fileName1 = $themeLocation.'/txtfolder/file1.txt';
if(is_file($fileName1)){
echo 'It does exist';
} else {
echo 'Error';
} | You are trying to check it by URL, which makes no sense to `is_file()` which expects local path. By the way I'd use `file_exists()` instead.
Try:
$fileName1 = TEMPLATEPATH . '/txtfolder/file1.txt'; | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "include, filesystem, wp filesystem, template include"
} |
Script loaders vs wp_enqueue_script
My Wordpress theme has a lot of .js scripts running and it takes plenty of time to load them all one by one. I would love to use a script loader like HeadJS or yepnopejs to speed things up.
But... what about wp_enqueue_script? I'm using it to load every single script (and I believe that's the BEST & ONLY way to go?).
Won't loading scripts using script loader instead of wp_enqueue_script create any conflicts with plugins, widgets etc.?
What about enqueuing the script loader itself? | * If this is for your personal blog only, then just use a plugin that minifies and concatenates JS.
* If it's for a theme you're building, then if the scripts are custom, or small & unlikely to be used by other plugins, merge them all into a single .js file, and load it in the footer.
A more hardcore method would be to pick up registered scripts from the `$wp_scripts` global, unregister them all, and concatenate them into one file (or load them with headjs, whatever way you want to go). Here are some ideas if you go this way... | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "javascript, wp enqueue script"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.