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

mdgross on "Remove "At a Glance" Theme Name"

$
0
0

I would like to remove the theme name from "At a Glance." The code I was using (see below) stopped working after the WordPress 3.8 update. It appears that this text is no longer filtered by ngettext.

add_filter('ngettext', 'remove_theme_from_dash');

function remove_theme_from_dash($text)
{
	if(preg_match('/Theme.*with.*widgets/', $text))
	{
		return '';
	}
	return $text;
}

I would prefer to remove the text entirely as opposed to hiding it with CSS. Thank you.


m00nshine on "Adding admin-menu for plugin"

$
0
0

Hi,

i have created a Wordpress-Plugin and now I am solving some open issues. I have used "DX Plugin Base" as base for my plugin.

My plugin has ist own menu in wordpress-backend.
It is working, but I think I didn't make it right.
Please find below the relevant code I use for my admin-menu:

class myplugin_Plugin_Base {

  function __construct() {

    // register admin pages for the plugin
    add_action( 'admin_menu', array( $this, 'myplugin_admin_pages_callback' ) );

  }

  // Menüpunkte im Wordpress-Backend bzw. Dashboard registrieren
  function myplugin_admin_pages_callback() {
    add_menu_page(__( "myplugin", 'myplugin' ), __( "myplugin", 'myplugin' ), 'edit_themes', 'myplugin_setup', array( $this, 'myplugin_setup' ), 'dashicons-cart' );
  }

  function myplugin_setup() {
      include_once( myplugin_PATH . '/myplugin-backend.php' );
  }

}

I only want to have ONE single menu-item.
I have read somewhere, that I have to create a top-level-menu, like I did with the code above.
Also I would have to create a sub-level-menu item?

I don't know. Could anybody help me with it?

danetidwell on "Change default Posts edit.php filter landing"

$
0
0

I did a google search for possible solutions but I'm not sure if I'm phrasing it correctly, as nothing really showed up that addressed changing the default, only adding new filters.

When a user clicks on "Posts", the default view of "all posts" loads. Is there a function code snippet that would change this default to "scheduled" or "draft"?

I know this is a usability discussion, but I have editors that when they click on "Posts", they never see the ones that are pending review because they are so far down the "all posts" list, so I'd like for the default to show them what they need to edit… first.

Will on "Remove "insert into button" in media uploader for custom post types"

$
0
0

Looking for a way to remove the insert into post button in the media uploader for a specific custom post type. I can do it when the post type is in the url but when you edit a post, the post type isn't in the url.

ex.
post.php?post=27&action=edit

I tried $post, $typenow and $current_screen but the only one that works anywhere so far is $_REQUEST['post_type']. Not sure if part of it is using just add_action('admin_head', 'remove_insert_button_13247')

In any case, how do I detect the post type when editing a post, custom or other?

function remove_insert_button_13247() {
    echo '<style type="text/css">
        .media-frame a.button-primary {display:none;}
    </style>';
}
function get_current_post_type_13247() {
global $post, $typenow, $current_screen;
 if( $post && $post->post_type )
$post_type = $post->post_type;
 elseif( $typenow )
$post_type = $typenow;
elseif( $current_screen && $current_screen->post_type )
 $post_type = $current_screen->post_type;
elseif( $_REQUEST['post_type'] )
 $post_type = sanitize_key( $_REQUEST['post_type'] );
else
$post_type = '';
 return $post_type;
}
if ( get_current_post_type_13247() == 'listing') {
	add_action('admin_head', 'remove_insert_button_13247');
}

dudd, médecine blog on "Wordpress use external variable on functions.php"

$
0
0

I have a custom php page outside of wordpress, this page is connecting also to a external database, and get resultat form a sql query on a variable

i use require('../wp-blog-header.php') and require('../wp-load.php') to integrate with wordpress.

now i need to use this variable on the functions.php of my wordpress theme.

i do on my external page :

<head>
<connect to my database>
<my query>
<get resulte on $variable>
<require('../wp-blog-header.php')>
<require('../wp-load.php')>

but when i use $variable on my functions.php it do not work ?

ansielf on "Creating a plugin - how to upload a file in the plugin's settings page."

mmtomm on "WP_LIST_PAGE exclude pages with custom fields"

$
0
0

Hello,

I'm not good in coding and I did not find a easy solution for my need:

I have a woocoomerce site for which I want to setup a blog as well now. In my themes folder I found this file: template-archives.php with the following code which I had to modify to not list certain pages with those IDs found behind the "exclude" parameter:

echo avia_advanced_hr(false);
echo "<div class='one_third first archive_list'>";
echo "<h3>" . __('Available Pages','avia_framework') . "</h3>";
echo "<ul>";
wp_list_pages('title_li=&depth=-1&exclude=9,10,11,12,13,14,15,16,17,943,966,2350,2668' );
echo "</ul>";
echo "</div>";

As this will become impractical soon or later, I'm thinking about a plugin-free solution with a filter in functions.php or something similar. I want to ad a custom field like key=AvoidPageList value=true/false which can be assigned in the custom field section while editing a page. And the filter (or some function) should exclude those from wp_list_pages function.

Any Idea how to accomlish this?

btw. the reason why I want this is, that some pages like the start page will change often or are avaiable in different version for content experiments. Also some woocommerce pages like the checkout page or thank you page are retrieved by wp_list_page function which should not be there as they often contain google goal tracking etc.

Thanks for hints or codes
Tom

chrismichaels84 on "Grouping Topbar menus and removing notices bubble"

$
0
0

I am customizing my admin bar for my network so that it contains global links and such. I have been able to make it sing and dance so far, but there are two things that I cannot for the life of me figure out.

1.) I would like to group "MySites", The Individ Site Menu, and "+ New" under a single "Admin" menu. Is this possible without removing the current ones and rebuilding them from scratch under an Admin menu?

2.) More perplexing is that I have a bubble button at the right of the screen, just before the profile menu. It looks like an inverted comments bubble. I was able to remove the comments bubble, but I can't even find what this "Notices" bubble is to remove it. Anyone have any ideas?

Thank you!


unity100 on "Replacing/Overriding comments_template() from plugin"

$
0
0

Hi people,

i researched quite a bit but couldnt find an answer for this :

I want to replace the comment template of the theme (comments.php or whichever it is using) totally with my own function or comments.php in plugin.

In short, i want to totally override the theme's entire commenting template.

I was able to find this recommendation in stack exchange for this :

add_filter( "comments_template", "my_custom_function",0 );

However, this just filters the function, and my function just runs before comments_template, leading comments_template to STILL run after itself and load up the commenting template from the theme.

What should i use to accomplish this ?

Howdy_McGee on "TinyMCE 4.0 - Add Classes into Format Select"

$
0
0

With the introductions of TinyMCE 4.0 comes a new, nice Format Select which has a few categories:

Headers
- Header 1 through Header 6
Inline
- Bold through Code
Blocks
- Paragraph through Pre
Alignment
- Left through Justify

What I want to do is add a Classes Menu at the bottom (below the Alignment menu) which I can stack classes in the submenu. If I use the old fashion method:

$style_formats = array(
	array(
		'title' => '.large',
		'block' => 'p',
		'classes' => 'large',
		'wrapper' => false,

	)
);
$in['style_formats'] = json_encode( $style_formats );

The above will override everything inside my formats menu. If I print out the variable $in - style_formats doesn't exist - formats on the otherhand does exist, but as a string. I tried to json_decode it but it was no use.

How do I add a "Classes" menu appeneded to the pre-existing formats?

neon22 on "redirect_guess_404_permalink and custom types"

$
0
0

I have a new wordpress version of an old site. The old site had permalinks structure of:
website/artist_name
The new site uses:
website/portfolio/artist_name

The new site uses the "Options Framework" plugin and "Portfolio Posts" plugin to create a new type of Post called a Portfolio.

I want to redirect the old permalink structure to the new one. Its not easily done with simple rewrite rules but the Redirect plugin might work but needs constant maintaining.

The internal function redirect_guess_404_permalink is designed to solve exactly this problem but only for Posts.
FYI - Its in canononical.php under wp-includes.

So two things:
1. Can anyone help me in modifying this function so it works for custom types.
2. Would it be a good idea for this to be a feature request for a later version of Wordpress ?

rioforce on "Use get_background_image in src"

$
0
0

Hi, I have an image tag in the header.php file in my Wordpress child theme. I want to use the wordpress background image defined in the Admin panel as the img src.

I found where you can call the background image from PHP, but I put it in the quotes in the src, but that will not put the image there. It leaves the img src blank when I view source in Firefox.

https://codex.wordpress.org/Function_Reference/get_background_image

Basically, this is the code I wrote that did not work:

<img id="parallaxContainer" src="<?php get_background_image(); ?>" />

What am I doing wrong?

Thanks for the help! :D

ndh01 on "sanitizing a text field form but keep line breaks"

$
0
0

I have been using sanitize_text_field() to sanitize a text field in a form. I need to keep the line breaks in the form so I can use nl2br to place each line break on a new line when displaying back the data.

Any ideas on how to safely sanitize and yet preserve line breaks?

Thank you

chachalady on "Native gallery shortcode output- title attribute"

$
0
0

Hello,
I would like to avoid installation of any other gallery plugin since Native wordpress gallery does everything I need (I even managed to add fancybox class and rel ...) EXCEPT ONE THING :
- there is no title attribute (and I need one in a> tag ... )

I know it is a "wordpress way" now : gallery shortcode generate the output without title , text we write inside image title is outputed in 'alt' like this:

<a class="fancybox" href="http://www.mydomain.com/..my-image.jpg" rel="galleryGroup">
<img class="attachment-thumbnail" width="150" height="150" alt="MY TITLE" src="http://www.mydomain.com/..my-image-thumb.jpg">
</a>

I need this:

<a class="fancybox" title="MY TITLE" href="http://www.mydomain.com/..my-image.jpg" rel="galleryGroup">
<img class="attachment-thumbnail" width="150" height="150" alt="MY TITLE" src="http://www.mydomain.com/..my-image-thumb.jpg">
</a>

Since the title is "picked up" in alt there must be the way to use it and write/ echo it in title attribute.

I really need it to work with gallery shortcode, when inserting gallery to post or page.
( title attr. while inserting single image is not so important right now ... it can be added manualy if needed ...)

If it means to hack the core wordpress file - so be it.!
I can live with that one and only hack - I will add it when updating wordpress ...

If there is other way please help - I was browsing through forums for days now with no luck ( either I messed up with code or syntax or the solution was not what I need ..)

I believe the code for gallery shortcode output is in wp-includes/media.php - don't know how to get the title from the image data and display it as title attribute in tag ...

Thanks,
ChachaLady

robotrop on "function that returns score of most related post. (YARPP)"

$
0
0

I'm making the base of wordpress posts using Automatic Featured Image Posts Plugin. I added some functionality to the plugin, like post title = image name.

But some of the image names are very similar. Curently, I'm manually using YARPP to check the similarity score. I want to do it semi-automatic, something like: if it's over modify the title ($title = '!!'.$title; ).

----
In the readme.txt I found yarpp_related() but it returns (html ready) related items, without the score.

I tried to figure out which function could return the score of the most similar item (based only on title). Or a string containg the score. But, I feel so lost in the yarpp code.


ibetthisispublic on "Show only post from selected category"

$
0
0

Hi.

I have searched for about 10 hours now and even though I've found some category template hacks out there, the ones that kind of work still don't fix the problem.

The same problem/behaviour goes for standard posts as for Woocommerce product listings: when a base category is selected, WP shows all posts, even those from subcategories.

Even if I somehow manage to code a template that would list the desired products, the product counter would still be wrong because that's part of a different php file that's loaded before the template.

So I am looking for a hack/filter that would alter the core WP code so that when I list posts from a certain category, none from subcategories are returned. This is the behaviour I want for all posts on the site.

Thanks for reading.

gaklime on "unable to log on my admin page on wordpress site"

$
0
0

Hello, i wanna know what to do? my wordpress site is displaying: Forbidden

You don't have permission to access /wp-login.php on this server.

please help out!

yerlix on "custom message on quick edit"

$
0
0

On my site, I check if an array doesn't exceed 3 values. Now I want to doe this as well on the quick edit form.

So far, I get the message only when I refresh the browser.

The code I use when I save the quick edit:

if ( array_key_exists( 'speciality', $_POST ) ){
			    // update_post_meta( $post_id, 'med-spec', $_POST[ 'speciality' ] );
			    // inlezen specialiteiten
		        $specs = preg_split("/[\s,]+/", $_POST['speciality']);

		        // check of er maximum 3 ingevuld zijn
		        if (count($specs) < 4){
		            update_post_meta( $post_id, 'med-spec', $_POST[ 'speciality' ] );
		        } else {
		            $_SESSION['my_admin_notices'] = "<div class='error'><p>Maximum 3 specialiteiten!</p></div>";
		            return false;
		        }
			}

The code above checks if the array is maximum 3 values long and puts a message in the session when it is not.

On my page I recall the session:

function my_admin_notices(){
        var_dump($_SESSION['my_admin_notices']);
        if(isset($_SESSION['my_admin_notices'])) {
            print  $_SESSION['my_admin_notices'];
        } else {
           $value = '';
        }
        unset($_SESSION['my_admin_notices']);
    }
    add_action( 'admin_notices', 'my_admin_notices' );

But this shows the message only on refreshing the browser.

Is there a hook for this? Or must this be done through javascript?

guitavares on "Add custom taxonomy to "Links" (aka bookmarks)"

$
0
0

I enabled the Links Manager in my wordpress installation.
I use the Links as a way of managing banner ads. By using Link Categories I can display specific banners on the right place of the site.
What I am trying to do is to register a custom taxonomy ("clubs") to the Links post type (BTW: are "Links" a regular post-type just as "posts" or "pages"?)
I am trying to do this so I can extend a taxonomy I use on posts, to also be used on Links, this way I can relate posts to links and display the right ads for my post sidebar, based on the same taxonomy they share.
I tried using the function: register_taxonomy_for_object_type('clubs', 'links') but it does nothing. (I tried using links, link, Links, Link in the post_type parameter as well). 'clubs' is the correct name of a custom taxonomy I have already registered (via plugin).
I am also attaching that register function to the 'plugins_loaded' hook, so to make sure my 'clubs' taxonomy is correctly created by my plugin when I try to extend it to the Links.
I can't seem to find much help about this online, especially because the words "links" and "taxonomy" on my search terms return mainly other kind of topic that is not what I am trying to solve, so I created this topic.
Any help?

john_aku on "help needed edit file from plugin"

$
0
0

i am writing a plugin and i want it to have the possibility to change its css from a textarea in the plugin section.

I am able to code the metabox, the textarea(which loads the css file) but i cannot save it, when i press the button. The code is as follows. Please help me

add_action('add_meta_boxes', 'edit_meta_box');

function edit_meta_box() {
 add_meta_box("edit", "Editor", 'view_edit_box', "resp_edit", "normal");

}

function view_edit_box() {

	$file = stripslashes('style.css');

	$plugin_files = get_plugin_files($file);
	$file = validate_file_to_edit($file, $plugin_files);
	$real_file = WP_PLUGIN_DIR . '/' . $file;

	if( isset($_POST['newcontent']) ) {
		$newcontent = stripslashes($_POST['newcontent']);
		if ( is_writeable($real_file) ) {
				$f = fopen($real_file, 'w+');
				file_put_contents($f, $newcontent);
				fclose($f);
		}
		//echo $newcontent;
	}

	$content = file_get_contents($real_file );
	$content = esc_textarea($content);

	$html1 = '<form action="" method="post">
				<table class="form-table"><tbody><tr valign="top"><td>
				<textarea cols="85"
						  rows="80"
						  name="newcontent"
						  id="newcontent1" tabindex="1">'.$content.'
			 	</textarea>
				</td></tr></tbody>
			</table>
			<input type="submit" name="sub" value="Update File">
			</form>';
		echo $html1;	

}
Viewing all 8245 articles
Browse latest View live




Latest Images