Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all 8245 articles
Browse latest View live

graemebryson5 on "Custom Avatar Shortcode"

$
0
0

I'm using the following shortcode to pull in user avatars for a front-end dashboard in conjunction with 'WP User Avatar', which allows users to set their own avatar. I've set a new avatar for myself, yet I'm still seeing the default Mystery Man.

I wanted to know if anyone could perhaps spot any issues/conflicts that would stop the custom avatar being displayed? I'm completely stumped, so would massively appreciate some opinions.

// User Avatar
add_shortcode( 'current-avatar' , 'ss_get_current_avatar' );
function ss_get_current_avatar(){
    $user = wp_get_current_user();
    echo get_avatar( $id_or_email, $size, $default, $alt );
}

// Add class to avatar
add_filter('get_avatar','add_gravatar_class');

function add_gravatar_class($class) {
    $class = str_replace("class='avatar", "class='avatar welcome_avatar", $class);
    return $class;
}

Zipster on "Comments within Post for Certain Roles only"

$
0
0

I do not know if this is possible or if there is already a plugin out there.

Basically what I am looking for is a way to get a comment box within a post and then that comment that is left to be added to the post content.

I would also like the comment area within the post to be seen by 'Authors' or higher only.

Is this possible? Is there something out there which would work for me?

Thanks In Advance!

Blutarsky on "Insert post between posts"

$
0
0

I am attempting to use WP to manage a sort of conversation between two people. Each member in the conversation may post a "reply", hence the WP site on the index page will load all posts toe resemble a conversation.
The problem will occur once I'd like to insert a post (comment) between two existing posts..... is there a way to achieve this?
For example:
post 1
post 2
post 3
.....

How to insert a post between 2 & 3???

jepper on "custom_pre_get_posts query modification gives 404"

$
0
0

Hi

I've got a nasty problem that i can't seem to get rid of.

In an attempt to remove slugs for a custom post type I've followed this guide:

http://ryansechrest.com/2013/04/remove-post-type-slug-in-custom-post-type-url-and-move-subpages-to-website-root-in-wordpress

We got this working but with updates it somehow broke. Now the WP_Query modifications result in a 404 error page, while the post exists!

So this is my function, with debug code:

function custom_pre_get_posts($query) {
    global $wpdb;

    if(!$query->is_main_query()) {
        return;
    }

    //echo '$query before: <pre>' . print_r($query, true) . '</pre>';

    $post_name = $query->get('category_name');
    //$post_name = $query->get('name');
    $post_name = str_replace(".html", "", $post_name);

    $post_id = $wpdb->get_var( $wpdb->prepare( 'SELECT * FROM ' . $wpdb->posts . ' WHERE post_name = %s LIMIT 1', $post_name ) ); 

    //echo '$post_name: <pre>' . $post_name . '</pre>';

    $post_type = $wpdb->get_var(
        $wpdb->prepare(
            'SELECT post_type FROM ' . $wpdb->posts . ' WHERE post_name = %s LIMIT 1',
            $post_name
        )
    );

   // echo '$post_type: <pre>' . $post_type . '</pre>';

    switch($post_type) {
        case 'product':
            $query->set('product', $post_name);
            //$query->set('name', $post_name);
            //$query->set('p', $post_id);
            //$query->set('page_id', $post_id);
            $query->set('post_type', $post_type);
            $query->is_single = true;
            $query->is_page = false;
            break;
    }

   echo '$query after: <pre>' . print_r($query, true) . '</pre>';

    return $query;
}

which results in a 404 with this query after:

WP_Query Object
(
    [query_vars] => Array
        (
            [category_name] => m-double-you-sachet-whey-isolate.html
            [error] =>
            [m] =>
            [p] => 0
            [post_parent] =>
            [subpost] =>
            [subpost_id] =>
            [attachment] =>
            [attachment_id] => 0
            [name] =>
            [static] =>
            [pagename] =>
            [page_id] => 21037
            [second] =>
            [minute] =>
            [hour] =>
            [day] => 0
            [monthnum] => 0
            [year] => 0
            [w] => 0
            [tag] =>
            [cat] =>
            [tag_id] =>
            [author] =>
            [author_name] =>
            [feed] =>
            [tb] =>
            [paged] => 0
            [comments_popup] =>
            [meta_key] =>
            [meta_value] =>
            [preview] =>
            [s] =>
            [sentence] =>
            [fields] =>
            [menu_order] =>
...
            [product] => m-double-you-sachet-whey-isolate
            [post_type] => product
        )
...
    [is_admin] =>
    [is_attachment] =>
    [is_singular] =>
    [is_robots] =>
    [is_posts_page] =>
    [is_post_type_archive] =>
    [query_vars_hash] => 60f1fdf5aebc76aba270391b0658101c
    [query_vars_changed] =>
    [thumbnails_cached] =>
    [stopwords:WP_Query:private] =>
    [query] => Array
        (
            [category_name] => m-double-you-sachet-whey-isolate.html
        )

)

I've removed some for brevity. Trying to load a post id with a valid ID does not work as well.

How do i go from here?
How do i debug it?

The post is valid and under the id as found by the function

Thanks!

mbalochm on "nextpage tag page ID needed"

$
0
0

I have used the '<!--nextpage-->' tag to split my page into 5 pages.

I am using a bookmarking plugin (http://codecanyon.net/item/wordpress-user-bookmarks-standalone-version/6584179)

where by a user of my site can bookmark a certain page of the website so it may be easier for them to find later or keep it for future reference.

The problem occurs that if they want to bookmark http://domain.com/examplepage/4/

the first page gets bookmarked which is http://domain.com/examplepage/

The plugin uses post->ID to bookmark a page.

Is there way to get the post->ID or make a post->ID for the nextpage tag.

s-design on "Sub Menus On Some Pages & Not Others - Using Page Templates"

$
0
0

I had a hard time figuring out how to place menus on only some pages and not all pages. I have now figured out a solution that I am happy with and so I am sharing it here, in case it could help others and to get feedback to help improve the idea.

Here is what I was trying to do:
I was trying to add six different sub menus to my site. I wanted each sub menu only accessed by clicking on "it's parent" link in the main menu. Here is an example of a website that is using this interface menu method that I am describing. When the site I have been working on goes live it will have this method here.

These are other features I wanted:
• I wanted it to be easy to add any of these sub menus to any page I wanted.
• I wanted to use a combo of the page and menu editors to make it easy to update any of the menus items in any of these sub menus in the future.
• I wanted the default to be: not showing any of these sub menus.
• I didn't want to use CSS display:none; to make the menus not show up (because I have read this could slows my site down, because they are still being loaded even though they don't show up. I don't know if this is true or not, but I wanted to try a different solution just in case).
• I also wanted my solution to work with the child theme I am using.

What I had tried - but couldn't get to work:
I tried to figure out multi site to solve this problem but it was way too complex.
I tried the solution on this support page http://wordpress.org/support/topic/custom-menus-on-different-pages shared by "teknohippy." This seemed like is would work great but I couldn't get the custom fields to work.

What I used to solve these challenges:
• New Page templates
• My child theme's functions.php file
• The admin menu editor and
• The admin page editors for each page

These are the steps I followed:

Step 1. In my functions.php file in my child theme I "registered" the six menus I wanted to add, like so:

register_nav_menus(array(
			'sub-menu-1'  => __('Page 1 Menu', 'catcheverest'),
			'sub-menu-2'  => __('Page 2 Menu', 'catcheverest'),
			'sub-menu-3'  => __('Page 3 Menu', 'catcheverest'),
			'sub-menu-4'  => __('Page 4 Menu', 'catcheverest'),
                        'sub-menu-5'  => __('Page 5 Menu', 'catcheverest'),
			'sub-menu-6'  => __('Page 6 Menu', 'catcheverest')
		)
);

Of course these names ("sub-menu-3", "Page 3 Menu", etc.) can be customized to fit your needs. These menu names should now show up in the wp-admin > in Apperance > menu.

Step 2. I created six duplicates of the default page template that was in my parent theme and put them in my child theme folder and renamed them like this (you can name them as you wish):

page1.php
page2.php
page3.php
page4.php
page5.php
page6.php

Note: If you are not using a child theme you could just put these in your theme file. BUT, if you are not using a Child Theme you really should put in the time and effort to learn how to create and use a child theme. It will save you tons of time in the future when it comes time to update your site. There is tons of info about this in the codex or just search about how to do it in google.

Step 3. I then opened each of the new page template files (that I put in my child theme) and changed the template name that I wanted to show up in the WP admin > page editors > template selector > drop-down menu > under "Page Attributes." For example:

I changed this comment line (at the top):

<?php
/**
 * The template for displaying all pages

to be this:

<?php
/**
 * Template Name: sub-menu-1

Then save them. They could easily be named something else, like "About Pages SubMenu Template" or whatever. The names you changed in these template files should now be showing up in: the WP admin > page editors > template selector > drop-down menu > under "Page Attributes."

Step 4. In each of the page template files I added code like this. I placed it where I wanted each menu to appear on each page template.

<div class="extra-sub-menus">
            <?php
                if ( has_nav_menu( 'sub-menu-1' ) ) {
                    $args = array(
                        'theme_location'  => 'sub-menu-1',
			'fallback_cb'	  =>  '',
                        'container_class' => 'menu-header-container',
                        'items_wrap'      => '<ul class="sub-menu-list">%3$s</ul>'
                    );
                    wp_nav_menu( $args );
                }
            ?>
</div>

Note: This coded is a little different depending on what menu page template I was adding this code to. Where you see "sub-menu-1" (in two spots) I switched it for each of the different sub menus that I registered in step 1 above, such as: sub-menu-2, sub-menu-3, sub-menu-4, etc.

I added the above code into template page1.php. In page2.php I added the same code but switched "sub-menu-1" to "sub-menu-2" In page3.php I switched it to "sub-menu-3" and so on for each of the other page template files.

Step 5. I went into the menu editor in the wp-admin (it is in Appearance > Menu) then created the six menus with the page links I wanted on each menu. Selected the location (the template) that I wanted each menu to go with. To make it easy I made the "location" a similar name to each menu. For example: I created a menu by the name of "sub-menu-1 links" and selected it's location/template to be "sub-menu-1" etc.

Step 6. I then styled the css of the menus using the "extra-sub-menus" and "sub-menu-list" classes (you can do a ton of styling changes with just these two classes in the code above). You could choose to do this step last once you know it is all functioning the way you want.

Step 7. Then in the admin, I went to the page editors of each of the pages I wanted a different menus to appear on and selected the relevant "menu page template." For example: I added four page links to "sub-menu-1" in the menu editor, so I went into page editor of each of those four pages and selected the corresponding page template for "sub-menu-1" in the Page Attributes - Template drop-down selection menu. I updated each page. Now I have "sub-menu-1" showing up on all the pages I added it to. And, this menu is not showing any where I did not add it. Awesome!

Step 8. Repeated step 7 for each of my other sub menus.

Done! Hope this helps someone else.

Disclaimer: I don't know how to create a plugin to do something like this. If anyone is aware of a plug in that does something like this, please share. I don't know much PHP or Javascript, so I don't know if I can answer everyone's questions about this. If anyone has feedback to improve this method I would be happy to hear it. If I'm doing something "wrong" please share.

harvie316 on "I need help with this php code"

$
0
0
<?php if (!is_page('Contact Us')) { ?>
---ADSENSE CODE)
<?php } ?>

So I have 4 pages I dont want adsense showing, at the moment I can only add the "contact us" page for adsense not to show.

I have another 3 pages I want to hide adsense on, how do I work this code?

I tried doing

<?php if (!is_page('Contact Us', 'checkout')) { ?>

but that didnt work

thanks

jishi on "Wordpress Gallery Name: a hook or a hack?"

$
0
0

I need to show a name of Wordpress Gallery in a page. I wrote a plugin, which copies gallery shortcode from the page, if found, copies it to metas, where you can enter a param. It looks like [gallery columns="9" link="file" ids="85,84,83,82,81,80,79,78,77,76,75,74,73" name="PIR 2012"], and as a result it's shown on the page: http://ggg.jishi.ru/conditer .

The problem is: a client does not want to mess with any code, she want to have WYSIWYG editor, and the best way is to put an input field "Gallery name" to the gallery edit screen, and add the param "name" to a shortcode.

How can I do that? Any hooks, or any ideas what core files are to be changed? I haven't found any info in Codex.


spindogs on "Hierarchical custom post types - multiple post_name not queried correctly"

$
0
0

I have registered a custom post type with settings 'hierarchical' => true and 'supports' => array('title', 'editor', 'page-attributes')

The intention is to use this post type for hierarchical posts much like the "page" post type.

I have two posts with the following data:

"Post 1"
post_name: post-slug-here
url: /custom-post-type/post-slug-here/

"Post 2"
post_name: post-slug-here
url: /custom-post-type/parent-slug/post-slug-here/

When I visit the URL /custom-post-type/post-slug-here/ you expect to see "Post 1", however it is actually "Post 2" being served up by Wordpress.

A quick dump of $wp_query shows that Wordpress has found both "Post 1" and "Post 2" in its request, however it has incorrectly decided to use "Post 2" for the $post variable.

The request should really order by post_parent ASC, this way always prioritising the post with post_parent = 0 over a subpage

keendev on "Media Gallery Attachment Details Category Taxonomy"

$
0
0

Hi All,

I've got an interesting question I'd like to pose to you all, this might be a better fit for the advanced forum. However here goes:

Below is an image:

Media Gallery Example

I currently have Wp Media Gallery plugin installed.

Wp Media Gallery

Now inside this plugin the author registers the category taxonomy to the attachment post type, now thats all nice and dandy. This will make a category taxonomy text field show up in the attachment details section (highlighted in red in image above). Now what I'd like to know is:

1. Where is the code in the wordpress core which decides to add a field there?
2. Is it possible to add other fields their that will get saved as well. (Most likely a taxonomy)

Kind Regards

abdulkza250 on "How to have a publish container at the top and at the bottom of a post"

$
0
0

I am working on a website and the persons I am doing the website wants to have the publish button at the top above the title and one at the bottom. I want to know how can I accomplish this. I will appreciate any help I can get.

ecrump on "Contract Form Sending Daily eMails"

$
0
0

My site has been hacked I suspect , have been receiving this messages daily generated from the Contact Page . any suggestions on how to rid the site of this code?

Name uohmcas
Email redacted
Subject rpJrTFTeuPL
Message KIkyEb uvqtcwmynzdo,
Site http://margauxhessioncreative.com

Sent from (ip address): 5.9.145.107 ( static.107.145.9.5.clients.your-server.de )
Date/Time: March 16, 2014 1:05 am
Sent from (referer): http://margauxhessioncreative.com/?page_id=78
Using (user agent): Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4

probablepossible on "how can I switch the page title around?"

$
0
0

I manage a lot of wordpress sites for a lot of different people. And sometimes I have a lot of different sites open in different tabs in my browser. When the tabs become numerous they show fewer and fewer letters of the page title, and the first thing to disappear is the name of the site.
Right now, the admin side, the meta title will print out like this; dashboard < blog name -- wordpress

I would love to make the blog name come first, before the name of the page. That way I'd have a clue as to which of my thousand tabs to go to.

Rdited to ask--can I do this with .htaccess file?

Igor Sazonov on "Get Plugin Child Plugins architecture"

$
0
0

hi, all!
I have a trouble - i dont know how by "right" WP way create main plugin and make child plugins with possible to get all of installed child plugins in main plugin... maybe action or filter?

jimii on "Want to hide-unset media-menu & set featured img tab on upload mgr"

$
0
0

I need some help to try and hide or unset the .media-menu element and to style the .media-frame-content (left side panel of media upload mgr). I'd also like to hide the set featured image meta link... ideally hiding both of these from anyone that is not an admin (update core)

I've tried a small plugin and child theme colors css file to the point of exhaustion...

Is there a simple function edit that I can put in my child function file that will hide the tab and set featured image meta link?

I user twenty ten with wp property. Thank you for any guidance.


nvedia on "Remove special characters from post_title"

$
0
0

I have migrated from a custom cms by copying the data from custom cms DB to WP DB.
There was no column for post_name n custom cms so I copied post_title to post_name and replaced spaces with hyphen, removed commas etc
There are still some issues like there are intentional characters etc
(for eg halloween-ul-ultimul-bastion-al-sărbătorilor-nerom)

I do see that if I go to admin and edit the post, there is an ajax request to wp-admin/admin-ajax.php and function get_sample_permalink_html is called to get the modified post_name to be used
So, I supply in the input "helloworld,%$123", it changes it to "helloworld123"

I wanted to know is there a way to apply the same logic to my current post_name column(a mysql update query?) as there are more than 40000 rows and doing it manually from admin is not possible
All I want to do is update my current date in wp_posts.post_name so that all names are fine as per WP standards

vmpk1 on "PageNavi help,WP plugin"

$
0
0

cant figur out how to use PageNavi,the plugin is activated but not showing up on any of my pages.i am not good at coding,please be specific.

janfeng on "What to make this work ? /%postname%/"

$
0
0

add_action('admin_print_footer_scripts','eg_quicktags');
function eg_quicktags() {
?>
<script type="text/javascript" charset="utf-8">
edButtons[edButtons.length] = new edButton( 'button', 'postname', '/%postname%/', '', '' );
</script>
<?php
}

websupporter on "admin_enqueue_scripts hook & internationalization"

$
0
0

Hi everyone,
I am currently struggeling with a small problem. Well, I've coded a workaround, but I am not very happy about it and I would appreciate your thoughts on this.

I am programming a plugin, which supports internationalization. This plugin adds also menus on the Adminpage. For the dashboard I run the following functions:

  • add_menu_page()
  • The action hook "admin_enqueue_scripts"

So, this is what happens:
add_menu_page( __( 'Menu Title', 'textdomain' ), __( 'Menu Title', 'textdomain' ), 'edit_posts', 'slug', 'admin_output_index', SF_URL . 'icon.png', 81 );

I add a menupage with the translateable Title 'Menu Title'. And I add some submenupages.

In order to load my styles and Javascripts only on my menupage und subpages I use the action hook "admin_enqueue_scripts":

add_action( 'admin_enqueue_scripts', 'adminscripts' );
function adminscripts( $hook ){
	if( !in_array( $hook, array( 'toplevel_page_menu-title' ) ) )
		return;
	/* Register Scripts and Styles */
}

The $hook tells me, wether I am on one of my adminpages or not. My hooks are placed in an array. If the hook is not found in this array, my scripts and styles won't load.

I've expected this hook to be stable, but it isn't when it comes to internationalization, because part of the hook derives from the second "add_menu_page"-Parameter:
_( 'Menu Title', 'textdomain' )

So, in the moment, I run this script on another language, the hook changes and my scripts doesn't load. For now, my "workaround" is simply not to translate the second parameter, but this is a rather poor solution.

I am not quite sure, wether I shall call this a "bug" in WordPress or if I do not quite understand the whole "hook"-idea. But, before I now start to open a ticket or report to the core developers, I think its better to discuss this here.

I am quite interested, what you guys think :)

All the best

mura- on "Call specific category posts by tag"

$
0
0

Hi there,

I'm building a new version for my blog and reorganizing category and tags structure.

Through inspecting the website stats and finding out the way people behave while browsing it I've come to the realization that I've got to create something very specific.

What I need is to call posts from categories using only specific tags. I'm not in a position where I can use subcategories, so I need to make the template behave so I can basically add a query where I can dinamically call all the posts under a category, but using a specific tag. (I.E. website.domain/category/tag/) I understand I could create *static* page templates with the code to call posts from cat=x which "has_tag=y" but since a large number of tags is involved that'd be crazy, so I need to do this "dinamically", by url (or link, for that matter)

While I've not found a way to do this yet, I managed to think of an alternative way to query posts within a cat and specific tag, please tell me what you think of it and if I'm in the right direction here (or dead wrong...)

I'm making a custom category.php with a new query. It will call the category using regular code args{'category'=> ID, ...} then I'll add tag argument, and while pretty permalinks won't let me add a tag variable through url, I can pass the tag using a _POST variable. tag => $_POST['taglink']

As I said, given the amount of tags the site carries it'd be crazy to do this manually, so I'll change the way I display these links in my menus, automatically adding a form instead of a link for each tag styling them to look like simple a href hyperlinks.

I searched the forum looking for a simpler solution, but I was unable to find anything related. Do you guys think i'm approaching the issue the right way? Did my post even make any sense to you at all? :S

Viewing all 8245 articles
Browse latest View live




Latest Images