Skip to main content
Became Hot Network Question
more supporting content
Source Link

I have used ACF hundreds of times but never to edit the meta description.

I have created a simple text field in ACF, then tried to use this script:

<?php
$meta_description = get_field('meta_description'); ?>

<?php if ($meta_description != '') : ?>

    <meta name="description" content="<?php echo $meta_description; ?>"/>

<?php else : ?>

    <meta name="description" content="This could be an interesting meta description"/>

<?php endif; ?>

But, it doesn't acknowledge the field, it simply does the 'else' from the if statement.

Here is a screenshot of my ACF set-up:

enter image description here

Do I need to sanitise the field or call it earlier or something? Not sure why this would work so well for all other fields but this one.

Here is the field being filled in on the pages:

enter image description here

Is this even possible?

Any help would be great!

Ta, Jason.

I have used ACF hundreds of times but never to edit the meta description.

I have created a simple text field in ACF, then tried to use this script:

<?php
$meta_description = get_field('meta_description'); ?>

<?php if ($meta_description != '') : ?>

    <meta name="description" content="<?php echo $meta_description; ?>"/>

<?php else : ?>

    <meta name="description" content="This could be an interesting meta description"/>

<?php endif; ?>

But, it doesn't acknowledge the field, it simply does the 'else' from the if statement.

Here is a screenshot of my ACF set-up:

enter image description here

Do I need to sanitise the field or call it earlier or something? Not sure why this would work so well for all other fields but this one.

Is this even possible?

Any help would be great!

Ta, Jason.

I have used ACF hundreds of times but never to edit the meta description.

I have created a simple text field in ACF, then tried to use this script:

<?php
$meta_description = get_field('meta_description'); ?>

<?php if ($meta_description != '') : ?>

    <meta name="description" content="<?php echo $meta_description; ?>"/>

<?php else : ?>

    <meta name="description" content="This could be an interesting meta description"/>

<?php endif; ?>

But, it doesn't acknowledge the field, it simply does the 'else' from the if statement.

Here is a screenshot of my ACF set-up:

enter image description here

Do I need to sanitise the field or call it earlier or something? Not sure why this would work so well for all other fields but this one.

Here is the field being filled in on the pages:

enter image description here

Is this even possible?

Any help would be great!

Ta, Jason.

Source Link

Using Advanced Custom Field (ACF) to insert meta description on each page

I have used ACF hundreds of times but never to edit the meta description.

I have created a simple text field in ACF, then tried to use this script:

<?php
$meta_description = get_field('meta_description'); ?>

<?php if ($meta_description != '') : ?>

    <meta name="description" content="<?php echo $meta_description; ?>"/>

<?php else : ?>

    <meta name="description" content="This could be an interesting meta description"/>

<?php endif; ?>

But, it doesn't acknowledge the field, it simply does the 'else' from the if statement.

Here is a screenshot of my ACF set-up:

enter image description here

Do I need to sanitise the field or call it earlier or something? Not sure why this would work so well for all other fields but this one.

Is this even possible?

Any help would be great!

Ta, Jason.