On the front page of my testing WordPress site I have 10 posts. When we click on the post title or post featured image, it takes us to that particular post .
I want to call a function on my plugin, when we click title or image.
Is there any add_action() for that ? or suggest me how can we achieve the result.
You can try overriding the function "get_permalink".
It can be found in the following file-
http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/link-template.php
Related
Friends, Hello.
I have an issue, i'm searching for an answer for 2 days now. I think I have checked all the 10 firsts google pages of 20 different requests by now.
So, this is it.
I have a custom post type named "Footballer".
I have created 2 "Posts" of that CPT, which are "Messi" and "Ronaldo".
My permalinks for these 2 footballers are "mysite.com/footballer/messi/" and "mysite.com/footballer/ronaldo/". It is OK for me.
Now, I want to add a child page "about" (or "stats", or anything) to my footballers and I want this page to be available by the link "mysite.com/footballer/messi/about" (just add the child page slug after the cpt post link).
Obviously, I want to create a single page "about", not one for every footballer I have, and in this page I would retrieve data for the specific footballer (by functions/shortcodes).
Nota: the cpt and values in this post are fictionnals, I know I would display the about/stats directly in the footballer cpt post. I am just trying to explain what I need -> a generic child page for a cpt, available by "mysite.com/cpt/cptpost/childpage".
How can I do it ? I s it even possible ?
Thanks for your help.
EDIT ;
As it is not possible with Divi, can I try to rewrite the URL of my subpage ? If my subpage url is "mysite/subpage/?foot=messi", can I make it appear "mysite/footballer/messi/subpage".
I tried this code, without success
function my_rewrite_url() {
add_rewrite_tag( '%foot%','([^&]+)' );
add_rewrite_rule(
'footballer/([^/]+)/subpage',
'index.php?pagename=subpage&foot=$matches[1]',
'top'
);
}
add_action( 'init', 'my_rewrite_url' );
You are looking for custom taxonomies on the custom post type.
I am working on a plugin that automatically attaches a featured image to a WordPress post after save (i.e. programmatically not using the Media Selector). The plugin uses the add_action( 'save_post_post', 'myFunction'); hook to save the image to the post.
The Gutenberg UI does not update the featured image thumbnail in the metabox on the right column.
I have tested and verified that the image is successfully updated and attached to the post, and does show if you manually reload the page.
From what I can tell, I need to tell Gutenberg the featured image has been changed in order for it to be updated in the view.
I have been unable to locate a hook or action I can use to trigger such a refresh after the user presses the "Save" button.
What is the appropriate way accomplish this refresh (from within my plugin PHP file)?
The way I see it, WordPress takes care of the update for you. Maybe you didn't use the right hook?
When I use the following, my posts have a default thumbnail, whenever I open a new plugin page:
function custom_add_thumbnail( $post_ID ) {
set_post_thumbnail($post_ID, 67);
return $post_ID;
}
add_action( 'save_post', 'custom_add_thumbnail' );
If this doesn't help, please share your code, maybe in pastebin, so I can investigate further.
I want to code a function to get a popup or tooltip which shows the featured image and the title of an internal link when you hover a link on a post or page.
Does anybody know if this is possible and knows how? I know you have to use some filter hook of Wordpress and to use get_post_field('post_title') and $image = get_the_post_thumbnail_url().
I think it can only be done with a function that has to be put in the functions.php.
I want to have ability to choose for each page what post should appear in a sidebar, from multiple posts type. So I understand that I need a meta box with a dropdown list of all posts, but I don't know how to build this in functions.
I only found this solution which is quite similar to what I want, but this doesn't help me to much, because I can only choose from a single post type and display only in post pages.
There is a free plugin that will solve all of your woes. It's called ACF or Advanced Custom Fields. It has the ability to add a list of posts to a field and attach that field to pages. Here's how you'd do it:
First install the plugin and navigate to the custom fields screen. Setup your field exactly like this:
Then in the options below that section you need to select these options:
That will tell ACF to put the field only on pages. After you have set that up you will get a little sidebar block like this:
You can then select each post for the page and it will return that object on the frontend. You do need to use a little code to get the frontend to spit out the posts you need. Here is the code to get a frontend option from ACF. Inside of the sidebar.php file you need to add this code:
global $post; // Get the global post object
$sidebar_posts = get_field('posts', $post->ID); // Get the field using the post ID
foreach($sidebar_posts as $sidebar_post){ // Loop through posts
echo $sidebar_post->post_title; // Echo the post title
}
This will simply loop through the posts you select and echo out the title. You can do more with this by adding some other Wordpress post functions using setup_postdata(). This will allow you to do things like the_title() and the_content().
Hope this helps!
Hi I am reading Building wordpress themes from scratch in order to understand theme development.I got to a point in the book where it explains how to create the custom post type pages.And the author mentions that this function is required in order to display the page:
add_action('init' , 'director_rewrite');
function director_rewrite(){
global $wp_rewrite;
$wp_rewrite->add_permastruct('typename','typename/%year%%postname%/' , true , 1);
add_rewrite_rule('typename/([0-9]{4})/(.+)/?$','index.php?typename=$matches[2]', 'top');
$wp_rewrite->flush_rules();
}
I have deleted the function and the page still display corectly without it.That leads me to belive that I do not understand wha this actualy does.
So is this function required to properly display custom post type pages?If so what does it do?
It adds rewrite rule for the permalinks structure of your page. If you remove it, the page still show correctly, but link towards your page is different!