I actually searched on the web about meta boxes but didnt find the thing I want since they were page and post specific . So I am actually searching for a thing(meta box or whatever) which will provide me a simple text field in the admin panel and when I enter the link of the youtube video and hit submit the video would appear in the HEADER of my blog . So which tool will let me to do the thing I described ?
It is actually "custom fields" what I meant here . For each post you can add a custom field and in the header you can use each's value via 'get_post_custom_values' function .
Related
I'm trying to work out how to edit the download button link that sits directly underneath the order title, in the order details section of the thank you page.
So if you make an order in Woocommerce, for a product that is downloadable, you get a "Thank you. Your order has been received" box, then under it, you get an "Order Details" box.
In that order details box, it shows each product ordered, and if that product is downloadable, it shows a small "Download: Product name" link under the product title.
I want to hook/filter into that download link, and edit it ( changing the text mainly, but also restyling it).
I've tried finding the action that adds it, but can't seem to work out where it's based, and then how to filter into it to change it's appearance. I did also try to add a function that include a different download link using woocommerce_order_item_meta_end, then hide the old link, but can't work out how to get the product download link URL either.
Any help would be great, thanks!
There doesn't seem to be any filters to do that so you'd need to copy the \templates\order\order-downloads.php template file into your child theme folder and make modifications to the following line in that file.
case 'download-file':
echo '' . esc_html( $download['download_name'] ) . '';
break;
I am currently attempting to configure the settings of attachments to make it required and only one attachment attached to a post but all my changes did not have any good results.
I have looked into adding an action to attachment_register function and some documentation about attachments in Wordpress but still no positive results.
Personally, I would go with the ACF (Advanced Custom Fields) plugin to accomplish this.
You can use the plugin add a new required media upload (picture/file) meta field for posts.
In the settings for this new Custom Field group, you also use the plugin to remove the default "featured image" field from the edit post screen, to force the user to use your new required media upload function.
All that said, you will probably need to make adjustments to your theme template files to use the ACF functions to display the data on your site. This will probably be pretty straight forward as long as you have ability to alter you theme template files.
Hope that helps!
Building on Mike C's answer in regards to using ACF (Advanced Custom Fields) with a step by step walkthrough of how to achieve such a thing.
Install the Advanced Custom Fields Plugin
Once Activated you will see a new section in the Wordpress Left Menu
Click Custom Fields
First we need a field group, click Add New
Name this something relevant such as "Page Attachment"
Now Click Add Field and Fill out the fields, example below:
Field Label: Upload Attachment
Field Name: page_attachment
Field Type: File
Return Value: If you want someone to click a link to download, select File URL
Scroll Down To The Section Titled Locations
You mentioned that this should be on posts so I would recommend the below selections:
Post Type -> Is Equal To -> Post
Click Save/Update
Go To A Post, you will now see a button that reads Add File, you cannot update/create a post without having a file attached.
This is the admin work completed now we need to make the file appear in the post.
Now if you want the file to appear at the end of the post, under the header or even in the sidebar that is fine. Simply add the following code:
<p><a href="<?php the_field('page_attachment');?>" title="<?php the_title();?>">
Download Attachment
</a></p>
Obviously this is just a link that it echos, so this could be added to an image to make it seem a little more stylish, it's up to you. But this is the simple way of adding a file.
Now if you wanted to add this into the page content midway, you would either need to make a shortcode function to display it. Or you could add something like:
Download Now
And then add the following to the bottom of your post:
<p id="attachment"><a href="<?php the_field('page_attachment');?>" title="<?php the_title();?>">
Download Attachment
</a></p>
This means, whenever some clicks on the link that takes them to #attachment, it will jump them down to the bottom of the post where the download link is.
Any questions, let me know.
I'm pretty new to WordPress and building a site that is using a custom template. The template includes a large banner at the top which is uploaded via the page's "featured image".
I would like to add the page title on the top of this image(which is not an issue) but be able to specify if the title is positioned left or right(maybe a dropdown menu selection) when creating the page.
I've seen many suggestions for similar functionality using the plugin Advanced Custom Fields, but I'm unable to find a solution that doesn't involve an additional plugin.
Is there a reason why I can't just add in the functionality I need? Adding a plugin just seems a little overkill to me for such a small feature.
UPDATE:
Ok, after some poking around I found that there's a "custom fields" option that was not checked in the "screen options". My understanding is that these fields work as key value pairs that can be accessed in the template using get_post_meta($post_id, $key, $single); or a more specific example get_post_meta($post->id, 'my_dropdown_key', true);. I will test it out and report results.
Yes you can use the custom fields by checking from the top bar of the WordPress page admin section. However, this is not a good solution as it will likely be confusing after you have multiple custom fields which is sure.
You can use the custom meta box function for this and add the functionality to your page which is easier done through a plugin called advanced custom fields which you already seem to know.
So, if you don't want to use the plugin instead you want to do it custom then there is a function callend add_meta_box. This function allows you to add a seperate box on a specific post_type.
For Quick Tutorial: https://www.sitepoint.com/adding-custom-meta-boxes-to-wordpress/
Hope this gives an overview on meta boxes. Thanx.
For those also learning how to do this, you must enable "custom fields" from the "screen options" in the top right corner of the admin screen. You can then create fields based on key value pairs and retrieve them using the get_post_meta($post_id, $key, $single) function.
For example, you can create a new custom field with the key "blue_text" and value " 'color: blue;' ". You can then access this value and apply the style in the markup like so:
<h1 style=<?php echo get_post_meta(get_the_ID(), 'blue_text', true); ?>>
This text is blue!
</h1>
This obviously is not the dropdown that I had originally described, but it is a simple way to add styles to a specific page in a template using custom fields with no additional plugin, so this works for me.
UPDATE:
The accepted answer using meta boxes is a much better solution and should be considered before this route.
I am creating custom post types in WordPress using the "Types" plugin. Those post types are not supposed to have a post page associated with them that the user would navigate to by default when clicking a particular post link. They are supposed to be merely titles that I am displaying in a grid and that should link out to separate sites. Every post title has an individual link associated with it. I am styling those post titles using the "Grid Element" creator of the "Visual Composer" plugin, so I can set which attributes of the post I want to display (in my case only the title).
When I am creating the post type, I am adding a custom field for the link url that I can then set when I create the individual post. However, I am not seeing an option to set that custom link to be the link for the post itself. I can add the link as a separate UI element of the post but I want the post title itself to be the link. Is this possible and how?
Very possible, but you will have to do some coding of your own, rather than relying on visual composer. Within the template you are using, in the loop that pulls the posts, you need to grab the meta data from that field for the current post:
<?php
// loop stuff here...
$link = get_post_meta(get_the_id(), your-key-here, true);
echo '<p>'.the_title().'</p>';
// other loop stuff...
?>
In the above, your-key-here refers to the name of the custom field you've set up for the link that gets set by the post author. The above also assumes you know enough about WordPress to know where you need to edit this code in, in the template. The code does not check for empty values and handle with a fallback, so yes, this code can be improved upon, but it sill do what you've asked in the question.
EDIT: A link for reference regarding pulling meta data/custom fields data; https://developer.wordpress.org/reference/functions/get_post_meta/
I have found numerous tutorials accross the web regarding how to add and remove fields from the 'contact info' section of the author profile page in the admin utilizing some code in the fuctions.php file. However, I cannot find anything regarding how to do the same in the 'about yourself' section of the author profile page. I specifically want to create an 'extended bio' text area to appear right below the standard 'biographical info' text area.
could someone point me in the right direction?
thx!
Use add_action("edit_user_profile", "my_form_fields_func") to place form fields below the bio textarea. Use add_action("edit_user_profile_update", "my_form_capture_func") to capture the form data. If you need to validate and add errors use the action hook user_profile_update_errors.