I'm trying to find out what action hook/filter I can use to insert content on the admin "edit.php" page (i want to place a few links above the 'posts' table)? I've found "edit_form_after_title" and "edit_form_after_editor" (these do exactly what I want to do, but they are for posts.php, not edit.php).
With the help of this answer: How do you create a custom edit.php / edit pages page
I came up with this:
<?php
# Called only in /wp-admin/edit.php pages
add_action( 'load-edit.php', function() {
add_filter( 'views_edit-talk', 'talk_tabs' ); // talk is my custom post type
});
# echo the tabs
function talk_tabs() {
echo '
<h2 class="nav-tab-wrapper">
<a class="nav-tab" href="admin.php?page=guests">Profiles</a>
<a class="nav-tab nav-tab-active" href="edit.php?post_type=talk">Talks</a>
<a class="nav-tab" href="edit.php?post_type=offer">Offers</a>
</h2>
';
}
?>
And it looks like this:
If you just wanted to add to the post title link you could do something like this
if (is_admin()) {
add_filter('the_title', function($title) {
return $before_title . $title . $after_title;
});
}
however, it doesn't sound like you want to add text to the title link.
To add html after the title and before the actions links, you could do like this
if (is_admin()) {
add_filter('post_row_actions', function($args) {
// echo your custom content here
return $args; // and dont forget to return the actions
});
}
There is also page_row_actions for the page edit screen (post_row_actions is only for posts)
As far as adding stuff before the title, I don't see a hook/filter to do that. See wp-admin/class-wp-posts-list-table.php line 463 function single_row if you want to look for yourself.
Related
I want to add a little code to the "Before Header Content hook" but I don't know where that is... Can you please help me?
Try:
add_action('init', 'process_post');
function process_post()
{
echo "test";
}
this is a modified version of #ajay 's solution
if you are going to use this, then you have to make sure that the current user is not an admin using is_admin() function.. and only display it if he is not an admin ...
why !?
because if you didn't, it may mess up the wp-admin of your website..
add_action('init', 'process_post');
function process_post()
{
if (!is_admin()) {
echo "test";
}
}
This could be tricky simply because every theme differs with how the loop is displayed, however you could create a plugin to use the loop_start action, which is called before the first post of the standard WP loop:
add_action( 'loop_start', 'test_loop_start' );
function test_loop_start( $query ){
echo 'this is my inserted text';
}
Now using this would display it every single time the loop is called (whether on a page, a post, category page, search page, etc.), which you may not want.
add_action( 'loop_start', 'test_loop_start' );
function test_loop_start( $query ){
if(is_category() OR is_singular()) {
echo 'this is my inserted text';
}
}
I want to separate the three columns and each column having five rows in footer area of my wordpress site.. I don't know how to use short code for that.. Can anyone help me..
For example Like this footer I need using shortcode..
If you're intending to do it using a shortcode then use the following code to create it;
`<?php
function firstshortcode_function() {
*//Your Code Should Be Written Here!*
return 'My first shortcode';
}
add_shortcode('firstshortcode', 'firstshortcode_function');
?>`
.. and use this [firstshortcode] shortcode wherever you would like to call it.
Note: You can replace the function name with anything you like and replace the shortcode appropriately.
To add HTML content under it, use the following code;
<?php
function my_custom_shortcode( $atts ) {
/ Turn on buffering /
ob_start(); ?>
<div>
// YOUR HTML CODE GOES HERE
<h1>Test</h1>
<p>My content</p>
</div>
<?php
/ Get the buffered content into a var /
$sc = ob_get_contents();
/ Clean buffer /
ob_end_clean();
/ Return the content as usual /
return $sc;
}
add_shortcode( 'shortcode', 'my_custom_shortcode' );
?>
I am new in woo commerce. I have tried with this code But it is not working
function contact_concierge() {
return '<a class="fsfb" href="'.site_url().'">CONTACT CONCIERGE</a>';
}
add_action('woocommerce_after_cart', 'contact_concierge');
I want to add the button after the singple page add to cart table. PLease help me.
The closest place you can get it to is underneath the product title, using:
function contact_concierge() {
echo '<a class="fsfb" href="'.site_url().'">CONTACT CONCIERGE</a>';
}
add_action('woocommerce_single_product_summary', 'contact_concierge');
Screenshot:
Reference:
http://docs.woothemes.com/document/hooks/
<?php do_action( 'woocommerce_after_add_to_cart_button' ); ?>
and
<?php do_action( 'woocommerce_after_add_to_cart_form' ); ?>
Are actually much closer to what the OP was looking for... assuming I understood correctly. The former is directly after the add to cart button and is therefore inside the <form> element. The latter is after the </form> closing tag.
You can see them in the WooCommerce templates /single-product/add-to-cart/single.php as well as variable.php and grouped.php.
function contact_concierge() {
echo'<a class="fsfb" href="'.site_url().'">CONTACT CONCIERGE</a>';
}
add_action('woocommerce_after_add_to_cart_button', 'contact_concierge');
i have created a Custom Post type Movie, and Also created a page Movies and Showed all the movies on that page. Great….
“But the Problem is”, When I click on that movie, Its’ going on the same single.php page, and that’s what I don’t want, I want a Saprate Single.php file for this movie section and seprate others like news, videos, so tell what i’ll do for this
Create single-movie.php file in your theme. Put custom code in there.
For any other custom post type use single-{custom-post-type-slug}.php
heres how to do it.
Delete everything in your single.php insert the following, and create multiple single.php files for your needs.
[note: in_category('id of your category')
<?php
$post = $wp_query->post;
if ( in_category(‘3′) ) {
include(TEMPLATEPATH . ‘/single-photo.php’);
} elseif ( in_category(‘4′) ) {
include(TEMPLATEPATH . ‘/single-video.php’);
} else {
include(TEMPLATEPATH . ‘/single-default.php’);
}
?>
Good luck ^ ^
I am having trouble with the previous_post_link() and next_post_link() functionality. When there is no previous post, the function previous_post_link() does not display a link, likewise for the next_post_link() and the last post. I would like to have a placeholder image so that the design stays consistent.
Currently I have images of green arrows pointing left and right, I would like to place an image of a grey arrow if there are no more posts to go back to.
Is there a way to use the next_post_link()/previous_post_link() functions but not have the link removed.
I also wonder if there is a way for the links to cycle, so that if you come to the most recent post, the next post link would bring you back to the first post.
************ UPDATED ************
Here is the code, based on "silent's" advice (accepted answer) to use get_adjacent_post():
<?php
if(get_adjacent_post(false, '', true)) {
previous_post_link('%link','<img src="larr.gif"/>');
}
else {
echo '<img src="larr2.gif"/>';
};
if(get_adjacent_post(false, '', false)) {
next_post_link('%link','<img src="rarr.gif"/>');
}
else {
echo '<img src="rarr2.gif">';
};
?>
So you can "capture" what next_post_link() and previous_post_link() return using ob_start() and ob_get_clean(), then apply a conditional to it.
Code in practice:
$previous_string = "<-Back";
ob_start(); // start output buffering
previous_post_link("%link", $previous_string);
$previous_link = ob_get_clean(); // stop output buffering and store
if ($previous_link == '') {
echo '<span style="color: #ccc">' . $previous_string . '</span>';
} else {
echo $previous_link;
}
I never try this myself. However, you may refer to this post. It uses get_adjacent_post().
Why cant you try the below?
<div style="float:right"><?php if(get_previous_posts_link()) { previous_posts_link('Newer Entries »'); } else { echo 'No Newer Entries'; } ; ?></div>
Alternatively to display Next and Previous Post Links to Blog post you can easily do that. This is very well explained at globinch.com (WordPress Tips : How to Add Next and Previous Post Links to Blog? )
http://www.globinch.com/2010/10/12/wordpress-tips-how-to-add-next-and-previous-post-links-to-blog/