Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

worpdress custom field

2018amdbuild
 Share

Go to solution Solved by carbine,

If I understand you correctly, you are trying to add a field to allow someone to set a value within a post that will be used in CSS when displayed on the post page? If so, first you will need to create a custom field. It's pretty straight forward, but here's a quick tutorial on field creation: https://www.advancedcustomfields.com/resources/creating-a-field-group/

 

Once you have that field created, you'll want to pull it in on the post page, so single.php would be the file to bring it in. You can access the value of that field from within single.php using something like the following (swapping field_name with the name of your field):

 

<?php the_field('field_name'); ?>

If you want to use the CSS inline, you could do something along these lines:

<div style="<?php the_field('field_name'); ?>">Your content here.</div>

Hopefully this clarifies things a bit for you.

Hi, I'm a bit of a novice web developer, I use ACF,(Advanced Custom Fields) though I'm still new to it but what I would like to do it have a post with a ACF field where I enter some text that is read and added to the value of a particular css property or div class name of the same post the custom field is for.

 

e.g. div class="x" to div class "x y"

 

essentially it is to customize the css property of that particular post uniquely, so Im not looking for custom post types here.

 

Along with this idea another issue raised is whether or not this code keeps running past the "first page" of posts as I'm considering using load more or endless scrolling for index navigation.

 

I guess the parts I'm having difficulty with are how to make such a field in ACF, one which just holds some info but is not visible on the post - I get lost in ACF, and the other part being where (which document in the template) to be using the code in (single.php, index or other?) and how to go about the code itself? should I stick to php for this or go for javascript?

 

I'm open to any plugin solutions though I dontk  now of any that do quite what I need in this instance.

Link to comment
Share on other sites

Link to post
Share on other sites

If I understand you correctly, you are trying to add a field to allow someone to set a value within a post that will be used in CSS when displayed on the post page? If so, first you will need to create a custom field. It's pretty straight forward, but here's a quick tutorial on field creation: https://www.advancedcustomfields.com/resources/creating-a-field-group/

 

Once you have that field created, you'll want to pull it in on the post page, so single.php would be the file to bring it in. You can access the value of that field from within single.php using something like the following (swapping field_name with the name of your field):

 

<?php the_field('field_name'); ?>

If you want to use the CSS inline, you could do something along these lines:

<div style="<?php the_field('field_name'); ?>">Your content here.</div>

Hopefully this clarifies things a bit for you.

Link to comment
Share on other sites

Link to post
Share on other sites

14 hours ago, carbine said:

If I understand you correctly, you are trying to add a field to allow someone to set a value within a post that will be used in CSS when displayed on the post page? If so, first you will need to create a custom field. It's pretty straight forward, but here's a quick tutorial on field creation: https://www.advancedcustomfields.com/resources/creating-a-field-group/

 

Once you have that field created, you'll want to pull it in on the post page, so single.php would be the file to bring it in. You can access the value of that field from within single.php using something like the following (swapping field_name with the name of your field):

 


<?php the_field('field_name'); ?>

If you want to use the CSS inline, you could do something along these lines:


<div style="<?php the_field('field_name'); ?>">Your content here.</div>

Hopefully this clarifies things a bit for you.

Hi thanks for the solution, I had actually figured out the solution already - which is the same as yours - but forgot about this post, thank you for the help though.

Link to comment
Share on other sites

Link to post
Share on other sites

5 minutes ago, 2018amdbuild said:

Hi thanks for the solution, I had actually figured out the solution already - which is the same as yours - but forgot about this post, thank you for the help though.

No problem! Glad you got it all sorted out. Happy New Year!

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share


×